Powerful Python

Book description

Once you've mastered the basics of Python, how do you skill up to the top 1%? How do you focus your learning time on topics that yield the most benefit for production engineering and data teams—without getting distracted by info of little real-world use? This book answers these questions and more.

Based on author Aaron Maxwell's software engineering career in Silicon Valley, this unique book focuses on the Python first principles that act to accelerate everything else: the 5% of programming knowledge that makes the remaining 95% fall like dominos. It's also this knowledge that helps you become an exceptional Python programmer, fast.

  • Learn how to think like a Pythonista: explore advanced Pythonic thinking
  • Create lists, dicts, and other data structures using a high-level, readable, and maintainable syntax
  • Explore higher-order function abstractions that form the basis of Python libraries
  • Examine Python's metaprogramming tool for priceless patterns of code reuse
  • Master Python's error model and learn how to leverage it in your own code
  • Learn the more potent and advanced tools of Python's object system
  • Take a deep dive into Python's automated testing and TDD
  • Learn how Python logging helps you troubleshoot and debug more quickly

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who This Book Is For
    2. The Two Levels of Learning
    3. Our Strategy in This Book
    4. What’s Not Covered
    5. Getting the Most Out of This Book
    6. Conventions Used in This Book
    7. Using Code Examples
    8. O’Reilly Online Learning
    9. How to Contact Us
    10. Acknowledgments
  2. 1. Scaling with Generators
    1. Iteration in Python
    2. Generator Functions
      1. Advancing next()
      2. Converting to a Generator Function
      3. Do You Need Generators?
    3. Generator Patterns and Scalable Composability
      1. Text Lines to Dicts
      2. Composable Interfaces
      3. Fanning Out
      4. Fanning In
    4. Python Is Filled with Iterators
    5. The Iterator Protocol
    6. Conclusion
  3. 2. Creating Collections with Comprehensions
    1. List Comprehensions
    2. Formatting for Readability (and More)
    3. Multiple Sources and Filters
      1. Independent Clauses
      2. Multiple Filters
    4. Comprehensions and Generators
    5. Dictionaries, Sets, and Tuples
    6. Conclusion
  4. 3. Advanced Functions
    1. Accepting and Passing Variable Arguments
      1. Argument Unpacking
      2. Variable Keyword Arguments
      3. Keyword Unpacking
      4. Combining Positional and Keyword Arguments
    2. Functions as Objects
    3. Key Functions in Python
    4. Conclusion
  5. 4. Decorators
    1. The Basic Decorator
      1. Generic Decorators
      2. Decorating Methods
    2. Data in Decorators
      1. Accessing Inner Data
      2. Nonlocal Decorator State
    3. Decorators That Take Arguments
    4. Class-Based Decorators
      1. Implementing Class-Based Decorators
      2. Benefits of Class-Based Decorators
    5. Decorators for Classes
    6. Conclusion
  6. 5. Exceptions and Errors
    1. The Basic Idea
      1. Handling Exceptions
      2. Exceptions for Flow Control
      3. Finally Blocks
      4. Dictionary Exceptions
    2. Exceptions Are Objects
    3. Raising Exceptions
    4. Catching and Re-Raising
    5. The Most Diabolical Python Antipattern
    6. Conclusion
  7. 6. Classes and Objects: Beyond the Basics
    1. Properties
      1. Property Patterns
      2. Validation
      3. Properties and Refactoring
    2. The Factory Patterns
      1. Alternative Constructors: The Simple Factory
      2. Dynamic Type: The Factory Method Pattern
    3. The Observer Pattern
      1. The Simple Observer
      2. A Pythonic Refinement
      3. Several Channels
    4. Magic Methods
    5. Rebelliously Misusing Magic Methods
    6. Conclusion
  8. 7. Automated Testing
    1. What Is Test-Driven Development?
    2. Unit Tests and Simple Assertions
    3. Fixtures and Common Test Setup
    4. Asserting Exceptions
    5. Using Subtests
    6. Conclusion
  9. 8. Module Organization
    1. Spawning a Module
    2. Creating Separate Libraries
    3. Multifile Modules
    4. Import Syntax and Version Control
    5. Nested Submodule Structure
    6. Antipattern Warning
    7. Import Side Effects
    8. Conclusion
  10. 9. Logging in Python
    1. The Basic Interface
      1. Log Levels
      2. Why Do We Have Log Levels?
    2. Configuring the Basic Interface
    3. Passing Arguments
    4. Beyond Basic: Loggers
    5. Log Destinations: Handlers and Streams
    6. Logging to Multiple Destinations
    7. Record Layout with Formatters
    8. Conclusion
  11. Parting Words
  12. Index
  13. About the Author

Product information

  • Title: Powerful Python
  • Author(s): Aaron Maxwell
  • Release date: November 2024
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098175702