Python 3 Object Oriented Programming


Python 3 Object Oriented Programming
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
$20.99
save 30%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
$39.99
save 50%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters

[ PACKT CLASSIC ]

  • Learn how to do Object Oriented Programming in Python using this step-by-step tutorial
  • Design public interfaces using abstraction, encapsulation, and information hiding
  • Turn your designs into working software by studying the Python syntax
  • Raise, handle, define, and manipulate exceptions using special error objects
  • Implement Object Oriented Programming in Python using practical examples

Book Details

Language : English
Paperback : 404 pages [ 235mm x 191mm ]
Release Date : July 2010
ISBN : 1849511268
ISBN 13 : 9781849511261
Author(s) : Dusty Phillips
Topics and Technologies : All Books, Application Development, Open Source, Python


Table of Contents

Preface
Chapter 1: Object-oriented Design
Chapter 2: Objects in Python
Chapter 3: When Objects are Alike
Chapter 4: Expecting the Unexpected
Chapter 5: When to Use Object-oriented Programming
Chapter 6: Python Data Structures
Chapter 7: Python Object-oriented Shortcuts
Chapter 8: Python Design Patterns I
Chapter 9: Python Design Patterns II
Chapter 10: Files and Strings
Chapter 11: Testing Object-oriented Programs
Chapter 12: Common Python 3 Libraries
Index
  • Chapter 1: Object-oriented Design
    • Object-oriented?
    • Objects and classes
    • Specifying attributes and behaviors
      • Data describes objects
      • Behaviors are actions
    • Hiding details and creating the public interface
    • Composition and inheritance
      • Inheritance
        • Inheritance provides abstraction
        • Multiple inheritance
    • Case study
    • Exercises
    • Summary
  • Chapter 2: Objects in Python
    • Creating Python classes
      • Adding attributes
      • Making it do something
      • Initializing the object
      • Explaining yourself
    • Modules and packages
      • Organizing the modules
        • Absolute imports
        • Relative imports
    • Who can access my data?
    • Case study
    • Exercises
    • Summary
  • Chapter 3: When Objects are Alike
    • Basic inheritance
      • Extending built-ins
      • Overriding and super
    • Multiple inheritance
      • The diamond problem
      • Different sets of arguments
    • Polymorphism
    • Case study
    • Exercises
    • Summary
  • Chapter 4: Expecting the Unexpected
    • Raising exceptions
      • Raising an exception
      • What happens when an exception occurs?
    • Handling exceptions
    • Exception hierarchy
      • Defining our own exceptions
    • Exceptions aren't exceptional
    • Case study
    • Exercises
    • Summary
  • Chapter 5: When to Use Object-oriented Programming
    • Treat objects as objects
    • Using properties to add behavior to class data
      • How it works
      • Decorators: another way to create properties
      • When should we use properties?
    • Managing objects
      • Removing duplicate code
      • In practice
      • Or we can use composition
    • Case study
    • Exercises
    • Summary
  • Chapter 6: Python Data Structures
    • Empty objects
    • Tuples and named tuples
      • Named tuples
    • Dictionaries
      • When should we use dictionaries?
      • Using defaultdict
    • Lists
      • Sorting lists
    • Sets
    • Extending built-ins
    • Case study
    • Exercises
    • Summary
  • Chapter 7: Python Object-oriented Shortcuts
    • Python built-in functions
      • Len
      • Reversed
      • Enumerate
      • Zip
      • Other functions
    • Comprehensions
      • List comprehensions
      • Set and dictionary comprehensions
      • Generator expressions
    • Generators
    • An alternative to method overloading
      • Default arguments
      • Variable argument lists
      • Unpacking arguments
    • Functions are objects too
      • Using functions as attributes
      • Callable objects
    • Case study
    • Exercises
    • Summary
  • Chapter 8: Python Design Patterns I
    • Design patterns
    • Decorator pattern
      • Decorator example
      • Decorators in Python
    • Observer pattern
      • Observer example
    • Strategy pattern
      • Strategy example
      • Strategy in Python
    • State pattern
      • State example
      • State versus strategy
    • Singleton pattern
      • Singleton implementation
      • Module variables can mimic singletons
    • Template pattern
      • Template example
    • Exercises
    • Summary
  • Chapter 10: Files and Strings
    • Strings
      • String manipulation
      • String formatting
        • Escaping braces
        • Keyword arguments
        • Container lookups
        • Object lookups
        • Making it look right
      • Strings are Unicode
        • Converting bytes to text
        • Converting text to bytes
      • Mutable byte strings
    • File IO
      • Placing it in context
      • Faking files
    • Storing objects
      • Customizing pickles
      • Serializing web objects
    • Exercises
    • Summary
  • Chapter 11: Testing Object-oriented Programs
    • Why test?
      • Test-driven development
    • Unit testing
      • Assertion methods
        • Additional assertion methods in Python 3.1
      • Reducing boilerplate and cleaning up
      • Organizing and running tests
      • Ignoring broken tests
    • Testing with py.test
      • One way to do setup and cleanup
      • A completely different way to set up variables
      • Test skipping with py.test
      • py.test extras
    • How much testing is enough?
    • Case Study
      • Implementing it
    • Exercises
    • Summary
  • Chapter 12: Common Python 3 Libraries
    • Database access
      • Introducing SQLAlchemy
        • Adding and querying objects
        • SQL Expression Language
    • Pretty user interfaces
      • TkInter
      • PyQt
      • Choosing a GUI toolkit
    • XML
      • ElementTree
        • Constructing XML documents
      • lxml
    • CherryPy
      • A full web stack?
  • Exercises
  • Summary

Dusty Phillips

Dusty Phillips is a Canadian freelance software developer, teacher, martial artist, and open source aficionado. He is closely affiliated with the Arch Linux community and other open source projects. He maintains the Arch Linux storefronts and has compiled the Arch Linux Handbook. Dusty holds a master's degree in computer science, with specialization in Human Computer Interaction. He currently has six different Python interpreters installed on his computer.

Sorry, we don't have any reviews for this title yet.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 6 submitted: last submission 02 Apr 2014

Errata type: Technical | Page number: 164 | Errata date: 08 Dec 10

The text says that the methods keys(), values(), and items() return iterator values; when in reality they return lists. Reference

 

Errata type: Typo | Page number: 17 | Errata date: 17 Jan 11

"This is a common first example of composition, bit it's not a very good one when it comes to designing computer systems."
Should actually be:
"This is a common first example of composition, but it's not a very good one when it comes to designing computer systems."

 

Errata type: Code | Page numbers: 51

print(secret_string.__plain_text) should be:
print(secret_string.__plain_string)

 

Errata type: Technical | Page number: 145

Replace "** means squared" with "**2 means squared"

Errata type: Code | Page numbers: 103

The last line of the code is: raise raise

It should be: raise


Errata Type: Typo | Page number 34

The name of the file in the content -i first_class.py actually refers to the file 1261_2_01-basic_class.py in the downloadable code bundle.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Python 3 Object Oriented Programming +    Programming Microsoft® Dynamics™ NAV =
50% Off
the second eBook
Price for both: $36.60

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Implement objects in Python by creating classes and defining methods
  • Separate different objects into a taxonomy of classes, and describe the properties and behaviors of those objects via the class interface
  • Design public interfaces using abstraction, encapsulation, and information hiding
  • Turn your designs into working software by learning the Python syntax
  • Share implementation using inheritance
  • Add functionality to the existing classes and built-ins using inheritance
  • Share similar code between classes by abstracting it into a parent class
  • Raise, handle, define, and manipulate exceptions using special error objects
  • Understand when to use object-oriented features, and more importantly when not to
  • Learn what design patterns are, and why they are different in Python
  • Uncover the simplicity of unit testing and why it's so important in Python
  • Utilize common Python 3 modules, libraries, and frameworks

In Detail

Object Oriented Programming is a very important aspect of modern programming languages. The basic principles of Object Oriented Programming are relatively easy to learn. Putting them together into working designs can be challenging.

This book makes programming more of a pleasure than a chore using powerful Python 3 object-oriented features of Python 3. It clearly demonstrates the core OOP principles and how to correctly implement OOP in Python.

Object Oriented Programming ranks high in importance among the many models Python supports. Yet, many programmers never bother learning the powerful features that make this language object oriented.

The book teaches when and how OOP should be correctly applied. It emphasizes not only the simple syntax of OOP in Python, but also how to combine these objects into well-designed software.

This book will introduce you to the terminology of the object-oriented paradigm, focusing on object-oriented design with step-by-step examples. It will take you from simple inheritance, one of the most useful tools in the object-oriented programmer's toolbox, all the way through to cooperative inheritance, one of the most complicated. You will be able to raise, handle, define, and manipulate exceptions.

You will be able to integrate the object-oriented and the not-so-object-oriented aspects of Python. You will also be able to create maintainable applications by studying higher level design patterns. You'll learn the complexities of string and file manipulation, and how Python distinguishes between binary and textual data. Not one, but two very powerful automated testing systems will be introduced to you. You'll understand the joy of unit testing and just how easy they are to create. You'll even study higher level libraries such as database connectors and GUI toolkits and how they apply object-oriented principles.

Harness the power of Python 3 objects; it's not just a scripting language

Approach

The book begins with the very foundations of OOP and then uses practical examples to show how to correctly implement Object Oriented Programming in Python. Many examples are taken from real-world projects. The book focuses on high-level design as well as the gritty details of the Python syntax. The provided exercises inspire the reader to think about his or her own code, rather than providing solved problems.

Who this book is for

If you're new to Object Oriented Programming techniques, or if you have basic Python skills and wish to learn in depth how and when to correctly apply Object Oriented Programming in Python, this is the book for you.

If you are an object-oriented programmer for other languages, you too will find this book a useful introduction to Python, as it uses terminology you are already familiar with.

Python 2 programmers seeking a leg up in the new world of Python 3 will also find the book beneficial, and you need not necessarily know Python 2.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software