Preface |
Acknowledgments |
About the Author |
Pythonic Thinking / Chapter 1: |
Know Which Version of Python You're Using / Item 1: |
Follow the PEP 8 Style Guide / Item 2: |
Know the Differences Between bytes and str / Item 3: |
Prefer Interpolated F-Strings Over C-style Format Strings and str.format / Item 4: |
Write Helper Functions Instead of Complex Expressions / Item 5: |
Prefer Multiple Assignment Unpacking Over Indexing / Item 6: |
Prefer enumerate Over range / Item 7: |
Use zip to Process Iterators in Parallel / Item 8: |
Avoid else Blocks After for and while Loops / Item 9: |
Prevent Repetition with Assignment Expressions / Item 10: |
Lists and Dictionaries / Chapter 2: |
Know How to Slice Sequences / Item 11: |
Avoid Striding and Slicing in a Single Expression / Item 12: |
Prefer Catch-AU Unpacking Over Slicing / Item 13: |
Sort by Complex Criteria Using the key Parameter / Item 14: |
Be Cautious When Relying on diet Insertion Ordering / Item 15: |
Prefer get Over in and KeyError to Handle Missing Dictionary Keys / Item 16: |
Prefer defaultdict Over setdefault to Handle Missing Items in Internal State / Item 17: |
Know How to Construct Key-Dependent Default Values with__ missing__ / Item 18: |
Functions / Chapter 3: |
Never Unpack More Than Three Variables When Functions Return Multiple Values / Item 19: |
Prefer Raising Exceptions to Returning None / Item 20: |
Know How Closures Interact with Variable Scope / Item 21: |
Reduce Visual Noise with Variable Positional Arguments / Item 22: |
Provide Optional Behavior with Keyword Arguments / Item 23: |
Use None and Docstrings to Specify Dynamic Default Arguments / Item 24: |
Enforce Clarity with Keyword-Only and Positional-Only Arguments / Item 25: |
Define Function Decorators with functools.wraps / Item 26: |
Comprehensions and Generators / Chapter 4: |
Use Comprehensions Instead of map and filter / Item 27: |
Avoid More Than Two Control Subexpressions in Comprehensions / Item 28: |
Avoid Repeated Work in Comprehensions by Using Assignment Expressions / Item 29: |
Consider Generators Instead of Returning Lists / Item 30: |
Be Defensive When Iterating Over Arguments / Item 31: |
Consider Generator Expressions for Large List Comprehensions / Item 32: |
Compose Multiple Generators with yield from / Item 33: |
Avoid Injecting Data into Generators with send / Item 34: |
Avoid Causing State Transitions in Generators with throw / Item 35: |
Consider itertools for Working with Iterators and Generators / Item 36: |
Classes and Interfaces / Chapter 5: |
Compose Classes Instead of Nesting Many Levels of Built-in Types / Item 37: |
Accept Functions Instead of Classes for Simple Interfaces / Item 38: |
Use @classmethod Polymorphism to Construct Objects Generically / Item 39: |
Initialize Parent Classes with super / Item 40: |
Consider Composing Functionality with Mix-in Classes / Item 41: |
Prefer Public Attributes Over Private Ones / Item 42: |
Inherit from collections.abc for Custom Container Types / Item 43: |
Metaclasses and Attributes / Chapter 6: |
Use Plain Attributes Instead of Setter and Getter Methods / Item 44: |
Consider @property Instead of Refactoring Attributes / Item 45: |
Use Descriptors for Reusable @property Methods / Item 46: |
Use _getattr_, _getattribute_, and _setattr_ for Lazy Attributes / Item 47: |
Validate Subclasses with init_subclass_ / Item 48: |
Register Class Existence with init_subclass_ / Item 49: |
Annotate Class Attributes with set_name_ / Item 50: |
Prefer Class Decorators Over Metaclasses for Composable Class Extensions / Item 51: |
Concurrency and Parallelism / Chapter 7: |
Use subprocess to Manage Child Processes / Item 52: |
Use Threads for Blocking I/O, Avoid for Parallelism / Item 53: |
Use Lock to Prevent Data Races in Threads / Item 54: |
Use Queue to Coordinate Work Between Threads / Item 55: |
Know How to Recognize When Concurrency Is Necessary / Item 56: |
Avoid Creating New Thread Instances for On-demand Fan-out / Item 57: |
Understand How Using Queue for Concurrency Requires Refactoring / Item 58: |
Consider ThreadPoolExecutor When Threads Are Necessary for Concurrency / Item 59: |
Achieve Highly Concurrent I/O with Coroutines / Item 60: |
Know How to Port Threaded I/O to asyncio / Item 61: |
Mix Threads and Coroutines to Ease the Transition to asyncio / Item 62: |
Avoid Blocking the asyncio Event Loop to Maximize Responsiveness / Item 63: |
Consider concurrent.futures for True Parallelism / Item 64: |
Robustness and Performance / Chapter 8: |
Take Advantage of Each Block in try/except/else/finally / Item 65: |
Consider contextlib and with Statements for Reusable try/finally Behavior / Item 66: |
Use datetime Instead of time for Local Clocks / Item 67: |
Make pickle Reliable with copyreg / Item 68: |
Use decimal When Precision Is Paramount / Item 69: |
Profile Before Optimizing / Item 70: |
Prefer deque for Producer-Consumer Queues / Item 71: |
Consider Searching Sorted Sequences with bisect / Item 72: |
Know How to Use heapq for Priority Queues / Item 73: |
Consider memoryview and bytearray for Zero-Copy Interactions with bytes / Item 74: |
Testing and Debugging / Chapter 9: |
Use repr Strings for Debugging Output / Item 75: |
Verify Related Behaviors in TestCase Subclasses / Item 76: |
Isolate Tests from Each Other with setUp, tearDown, setUpModule, and tearDownModule / Item 77: |
Use Mocks to Test Code with Complex Dependencies / Item 78: |
Encapsulate Dependencies to Facilitate Mocking and Testing / Item 79: |
Consider Interactive Debugging with pdb / Item 80: |
Use tracemalloc to Understand Memory Usage and Leaks / Item 81: |
Collaboration / Chapter 10: |
Know Where to Find Community-Built Modules / Item 82: |
Use Virtual Environments for Isolated and Reproducible Dependencies / Item 83: |
Write Docstrings for Every Function, Class, and Module / Item 84: |
Use Packages to Organize Modules and Provide Stable APIs / Item 85: |
Consider Module-Scoped Code to Configure Deployment Environments / Item 86: |
Define a Root Exception to Insulate Callers from APIs / Item 87: |
Know How to Break Circular Dependencies / Item 88: |
Consider warnings to Refactor and Migrate Usage / Item 89: |
Consider Static Analysis via typing to Obviate Bugs / Item 90: |
Index |
Preface |
Acknowledgments |
About the Author |
Pythonic Thinking / Chapter 1: |
Know Which Version of Python You're Using / Item 1: |
Follow the PEP 8 Style Guide / Item 2: |