Professional Python

Book description

Master the secret tools every Python programmer needs to know

Professional Python goes beyond the basics to teach beginner- and intermediate-level Python programmers the little-known tools and constructs that build concise, maintainable code. Design better architecture and write easy-to-understand code using highly adoptable techniques that result in more robust and efficient applications. Coverage includes Decorators, Context Managers, Magic Methods, Class Factories, Metaclasses, Regular Expressions, and more, including advanced methods for unit testing using asyncio and CLI tools. Each topic includes an explanation of the concept and a discussion on applications, followed by hands-on tutorials based on real-world scenarios. The "Python 3 first" approach covers multiple current versions, while ensuring long-term relevance.

Python offers many tools and techniques for writing better code, but often confusing documentation leaves many programmers in the dark about how to use them. This book shines a light on these incredibly useful methods, giving you clear guidance toward building stronger applications.

  • Learn advanced Python functions, classes, and libraries
  • Utilize better development and testing tools
  • Understand the "what," "when," "why," and "how"

More than just theory or a recipe-style walk-through, this guide helps you learn — and understand — these little-known tools and techniques. You'll streamline your workflow while improving the quality of your output, producing more robust applications with cleaner code and stronger architecture. If you're ready to take your Python skills to the next level, Professional Python is the invaluable guide that will get you there.

Table of contents

  1. Cover
  2. Introduction
    1. Who This Book Is For
    2. What This Book Covers
    3. How This Book Is Structured
    4. What You Need to Use This Book
    5. Conventions
    6. Errata
    7. p2p.wrox.com
  3. Part I: Functions
    1. Chapter 1: Decorators
      1. Understanding Decorators
      2. Decorator Syntax
      3. Where Decorators Are Used
      4. Why You Should Write Decorators
      5. When You Should Write Decorators
      6. Writing Decorators
      7. Decorating Classes
      8. Type Switching
      9. Summary
    2. Chapter 2: Context Managers
      1. What Is a Context Manager?
      2. Context Manager Syntax
      3. When You Should Write Context Managers
      4. A Simpler Syntax
      5. Summary
    3. Chapter 3: Generators
      1. Understanding What a Generator Is
      2. Understanding Generator Syntax
      3. Communication with Generators
      4. Iterables Versus Iterators
      5. Generators in the Standard Library
      6. When to Write Generators
      7. When Are Generators Singletons?
      8. Generators within Generators
      9. Summary
  4. Part II: Classes
    1. Chapter 4: Magic Methods
      1. Magic Method Syntax
      2. Available Methods
      3. Other Magic Methods
      4. Summary
    2. Chapter 5: Metaclasses
      1. Classes and Objects
      2. Writing Metaclasses
      3. Using Metaclasses
      4. When to Use Metaclasses
      5. The Question of Explicit Opt-In
      6. Meta-Coding
      7. Summary
    3. Chapter 6: Class Factories
      1. A Review of type
      2. Understanding a Class Factory Function
      3. Determining When You Should Write Class Factories
      4. Summary
    4. Chapter 7: Abstract Base Classes
      1. Using Abstract Base Classes
      2. Declaring a Virtual Subclass
      3. Declaring a Protocol
      4. Built-in Abstract Base Classes
      5. Summary
  5. Part III: Data
    1. Chapter 8: Strings and Unicode
      1. Text String Versus Byte String
      2. Strings with Non-ASCII Characters
      3. Other Encodings
      4. Reading Files
      5. Reading Other Sources
      6. Specifying Python File Encodings
      7. Strict Codecs
      8. Summary
    2. Chapter 9: Regular Expressions
      1. Why Use Regular Expressions?
      2. Regular Expressions in Python
      3. Basic Regular Expressions
      4. Grouping
      5. Lookahead
      6. Flags
      7. Substitution
      8. Compiled Regular Expressions
      9. Summary
  6. Part IV: Everything Else
    1. Chapter 10: Python 2 Versus Python 3
      1. Cross-Compatibility Strategies
      2. Changes in Python 3
      3. Standard Library Relocations
      4. Version Detection
      5. Summary
    2. Chapter 11: Unit Testing
      1. The Testing Continuum
      2. Testing Code
      3. Unit Testing Frameworks
      4. Mocking
      5. Other Testing Tools
      6. Summary
    3. Chapter 12: CLI Tools
      1. OPTPARSE
      2. ARGPARSE
      3. Summary
    4. Chapter 13: asyncio
      1. The Event Loop
      2. Coroutines
      3. Futures and Tasks
      4. Callbacks
      5. Task Aggregation
      6. Queues
      7. Servers
      8. Summary
    5. Chapter 14: Style
      1. Principles
      2. Standards
      3. Summary
  7. End User License Agreement

Product information

  • Title: Professional Python
  • Author(s): Luke Sneeringer
  • Release date: October 2015
  • Publisher(s): Wrox
  • ISBN: 9781119070856