Books & Videos

Table of Contents

  1. Prologue

    1. Chapter 1 The Python Data Model

      1. A Pythonic Card Deck
      2. How Special Methods Are Used
      3. Overview of Special Methods
      4. Why len Is Not a Method
      5. Chapter Summary
      6. Further Reading
  2. Data Structures

    1. Chapter 2 An Array of Sequences

      1. Overview of Built-In Sequences
      2. List Comprehensions and Generator Expressions
      3. Tuples Are Not Just Immutable Lists
      4. Slicing
      5. Using + and * with Sequences
      6. Augmented Assignment with Sequences
      7. list.sort and the sorted Built-In Function
      8. Managing Ordered Sequences with bisect
      9. When a List Is Not the Answer
      10. Chapter Summary
      11. Further Reading
    2. Chapter 3 Dictionaries and Sets

      1. Generic Mapping Types
      2. dict Comprehensions
      3. Overview of Common Mapping Methods
      4. Mappings with Flexible Key Lookup
      5. Variations of dict
      6. Subclassing UserDict
      7. Immutable Mappings
      8. Set Theory
      9. dict and set Under the Hood
      10. Chapter Summary
      11. Further Reading
    3. Chapter 4 Text versus Bytes

      1. Character Issues
      2. Byte Essentials
      3. Basic Encoders/Decoders
      4. Understanding Encode/Decode Problems
      5. Handling Text Files
      6. Normalizing Unicode for Saner Comparisons
      7. Sorting Unicode Text
      8. The Unicode Database
      9. Dual-Mode str and bytes APIs
      10. Chapter Summary
      11. Further Reading
  3. Functions as Objects

    1. Chapter 5 First-Class Functions

      1. Treating a Function Like an Object
      2. Higher-Order Functions
      3. Anonymous Functions
      4. The Seven Flavors of Callable Objects
      5. User-Defined Callable Types
      6. Function Introspection
      7. From Positional to Keyword-Only Parameters
      8. Retrieving Information About Parameters
      9. Function Annotations
      10. Packages for Functional Programming
      11. Chapter Summary
      12. Further Reading
    2. Chapter 6 Design Patterns with First-Class Functions

      1. Case Study: Refactoring Strategy
      2. Command
      3. Chapter Summary
      4. Further Reading
    3. Chapter 7 Function Decorators and Closures

      1. Decorators 101
      2. When Python Executes Decorators
      3. Decorator-Enhanced Strategy Pattern
      4. Variable Scope Rules
      5. Closures
      6. The nonlocal Declaration
      7. Implementing a Simple Decorator
      8. Decorators in the Standard Library
      9. Stacked Decorators
      10. Parameterized Decorators
      11. Chapter Summary
      12. Further Reading
  4. Object-Oriented Idioms

    1. Chapter 8 Object References, Mutability, and Recycling

      1. Variables Are Not Boxes
      2. Identity, Equality, and Aliases
      3. Copies Are Shallow by Default
      4. Function Parameters as References
      5. del and Garbage Collection
      6. Weak References
      7. Tricks Python Plays with Immutables
      8. Chapter Summary
      9. Further Reading
    2. Chapter 9 A Pythonic Object

      1. Object Representations
      2. Vector Class Redux
      3. An Alternative Constructor
      4. classmethod Versus staticmethod
      5. Formatted Displays
      6. A Hashable Vector2d
      7. Private and “Protected” Attributes in Python
      8. Saving Space with the __slots__ Class Attribute
      9. Overriding Class Attributes
      10. Chapter Summary
      11. Further Reading
    3. Chapter 10 Sequence Hacking, Hashing, and Slicing

      1. Vector: A User-Defined Sequence Type
      2. Vector Take #1: Vector2d Compatible
      3. Protocols and Duck Typing
      4. Vector Take #2: A Sliceable Sequence
      5. Vector Take #3: Dynamic Attribute Access
      6. Vector Take #4: Hashing and a Faster ==
      7. Vector Take #5: Formatting
      8. Chapter Summary
      9. Further Reading
    4. Chapter 11 Interfaces: From Protocols to ABCs

      1. Interfaces and Protocols in Python Culture
      2. Python Digs Sequences
      3. Monkey-Patching to Implement a Protocol at Runtime
      4. Alex Martelli’s Waterfowl
      5. Subclassing an ABC
      6. ABCs in the Standard Library
      7. Defining and Using an ABC
      8. How the Tombola Subclasses Were Tested
      9. Usage of register in Practice
      10. Geese Can Behave as Ducks
      11. Chapter Summary
      12. Further Reading
    5. Chapter 12 Inheritance: For Good or For Worse

      1. Subclassing Built-In Types Is Tricky
      2. Multiple Inheritance and Method Resolution Order
      3. Multiple Inheritance in the Real World
      4. Coping with Multiple Inheritance
      5. A Modern Example: Mixins in Django Generic Views
      6. Chapter Summary
      7. Further Reading
    6. Chapter 13 Operator Overloading: Doing It Right

      1. Operator Overloading 101
      2. Unary Operators
      3. Overloading + for Vector Addition
      4. Overloading * for Scalar Multiplication
      5. Rich Comparison Operators
      6. Augmented Assignment Operators
      7. Chapter Summary
      8. Further Reading
    7. Control Flow

      1. Chapter 14 Iterables, Iterators, and Generators

        1. Sentence Take #1: A Sequence of Words
        2. Iterables Versus Iterators
        3. Sentence Take #2: A Classic Interior
        4. Sentence Take #3: A Generator Function
        5. Sentence Take #4: A Lazy Implementation
        6. Sentence Take #5: A Generator Expression
        7. Generator Expressions: When to Use Them
        8. Another Example: Arithmetic Progression Generator
        9. Generator Functions in the Standard Library
        10. New Syntax in Python 3.3: yield from
        11. Iterable Reducing Functions
        12. A Closer Look at the iter Function
        13. Case Study: Generators in a Database Conversion Utility
        14. Generators as Coroutines
        15. Chapter Summary
        16. Further Reading
      2. Chapter 15 Context Managers and else Blocks

        1. Do This, Then That: else Blocks Beyond if
        2. Context Managers and with Blocks
        3. The contextlib Utilities
        4. Using @contextmanager
        5. Chapter Summary
        6. Further Reading
      3. Chapter 16 Coroutines

        1. How Coroutines Evolved from Generators
        2. Basic Behavior of a Generator Used as a Coroutine
        3. Example: Coroutine to Compute a Running Average
        4. Decorators for Coroutine Priming
        5. Coroutine Termination and Exception Handling
        6. Returning a Value from a Coroutine
        7. Using yield from
        8. The Meaning of yield from
        9. Use Case: Coroutines for Discrete Event Simulation
        10. Chapter Summary
        11. Further Reading
      4. Chapter 17 Concurrency with Futures

        1. Example: Web Downloads in Three Styles
        2. Blocking I/O and the GIL
        3. Launching Processes with concurrent.futures
        4. Experimenting with Executor.map
        5. Downloads with Progress Display and Error Handling
        6. Chapter Summary
        7. Further Reading
      5. Chapter 18 Concurrency with asyncio

        1. Thread Versus Coroutine: A Comparison
        2. Downloading with asyncio and aiohttp
        3. Running Circling Around Blocking Calls
        4. Enhancing the asyncio downloader Script
        5. From Callbacks to Futures and Coroutines
        6. Writing asyncio Servers
        7. Chapter Summary
        8. Further Reading
  5. Metaprogramming

    1. Chapter 19 Dynamic Attributes and Properties

      1. Data Wrangling with Dynamic Attributes
      2. Using a Property for Attribute Validation
      3. A Proper Look at Properties
      4. Coding a Property Factory
      5. Handling Attribute Deletion
      6. Essential Attributes and Functions for Attribute Handling
      7. Chapter Summary
      8. Further Reading
    2. Chapter 20 Attribute Descriptors

      1. Descriptor Example: Attribute Validation
      2. Overriding Versus Nonoverriding Descriptors
      3. Methods Are Descriptors
      4. Descriptor Usage Tips
      5. Descriptor docstring and Overriding Deletion
      6. Chapter Summary
      7. Further Reading
    3. Chapter 21 Class Metaprogramming

      1. A Class Factory
      2. A Class Decorator for Customizing Descriptors
      3. What Happens When: Import Time Versus Runtime
      4. Metaclasses 101
      5. A Metaclass for Customizing Descriptors
      6. The Metaclass __prepare__ Special Method
      7. Classes as Objects
      8. Chapter Summary
      9. Further Reading
    4. Appendix Support Scripts

      1. Chapter 3: in Operator Performance Test
      2. Chapter 3: Compare the Bit Patterns of Hashes
      3. Chapter 9: RAM Usage With and Without __slots__
      4. Chapter 14: isis2json.py Database Conversion Script
      5. Chapter 16: Taxi Fleet Discrete Event Simulation
      6. Chapter 17: Cryptographic Examples
      7. Chapter 17: flags2 HTTP Client Examples
      8. Chapter 19: OSCON Schedule Scripts and Tests