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
- 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
- Organizing the modules
- Who can access my data?
- Case study
- Exercises
- Summary
- Creating Python classes
- 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
- Basic inheritance
- 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
- Raising exceptions
- 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
- Python built-in functions
- 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 9: Python Design Patterns II
- Adapter pattern
- Facade pattern
- Flyweight pattern
- Command pattern
- Abstract factory pattern
- Composite pattern
- 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
- Strings
- 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
- Assertion methods
- 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
- Why test?
- Chapter 12: Common Python 3 Libraries
- Database access
- Introducing SQLAlchemy
- Adding and querying objects
- SQL Expression Language
- Introducing SQLAlchemy
- Pretty user interfaces
- TkInter
- PyQt
- Choosing a GUI toolkit
- XML
- ElementTree
- Constructing XML documents
- lxml
- ElementTree
- CherryPy
- A full web stack?
- Database access
- Exercises
- Summary