Please enable JavaScript.
Coggle requires JavaScript to display documents.
Effective Python (Pythonic Thinking (1: Know Which Version of Python…
Effective Python
Pythonic Thinking
1: Know Which Version of Python You're Using
Following the PEP 8 Style Guide
3: Know the Difference Between bytes, str and unicode
Write Helper Functions Instead of Complex Expressions
Know How to Slice Sequences
Avoid Using start, end and stride in a Single Slice
Use List Comprehensions Instead of map and filter
Avoid More Than Two Expressions in List Comprehensions
Consider Generator Expressions for Large Comprehensions
Prefer enumerate Over range
Use zip to Process Iterators in Parallel
Avoid else Blocks After for and while Loops
Take Advantage of Each Block in try/except/else/finally
Functions
Prefer Exceptions to Returning None
Know How Closures Interact with Variable Scope
Consider Generators Instead of Returning Lists
Be Defensive When Iterating Over Arguments
Reduce Visual Noise with Variable Positional Arguments
Provide Optional Behavior with Keyword Arguments
Use None and Docstrings to Specify Dynamic Default Arguments
Enforce Clarify with Keyword-Only Arguments
Classes and Inheritance
Prefer Helper Classes Over Bookkeeping with Dictionaries and Tuples
Accept Functions for Simple Interfaces Instead of Classes
Use
classmethod
Polymophism to Construct Objects Generically
Initialize Parent Classes with super
Use Multiple Inheritance Only for Mix-in Utility Classes
Prefer Public Attributes Over Private Ones
Inherit from collections.abc for Custom Container Types
Built-in Modules
Define Function Decorators with functors.wraps
Consider context lib and with Statements for Reusable try/finally Behavior
Make pickle Reliable with copyreg
Use data time Instead of time for Local Clocks
Use Built-in Algorithms and Data Structures
Use decimal When Precision is Paramount
Know Where to Find Community-Built Modules
Search PyPI (Python Package Index)
Install with pip3/pip
Metaclasses and Attributes
Use Plain Attributes Instead of Get and Set Methods
Consider
property
Instead of Refactoring Attributes
Use Descriptors for Reusable
property
Methods
Use
getattr
, get attribute
, and _setattr
for Lazy Attributes
Validate Subclasses with Metaclasses
Annotate Class Attributes with Metaclasses
Concurrency and Parallelism
Use subprocess to Manage Child Processes
Use Threads for Blocking I/O, Avoid for Parallelism
Use Lock to Prevent Data Races in Threads
Use Queue to Coordinate Work Between Threads
Consider Coroutines to Run Many Functions Concurrently
Consider concurrent.futures for True Parallelism
Production
Consider Module-Scoped Code to Configure Deployment Environments
Use repr Strings for Debugging Output
Test Everything with unittest
Consider Interactive Debugging with pdb
Profile Before Optimizing
Use tracemalloc to Understand Memory Usage and Leaks
Collaboration
Write Docstrings for Every Function, Class and Module
Use Packages to Organize Modules and Provide Stable APIs
Define a Root Exception to Insulate Callers from APIs
Know How to Break Circular Dependencies
Use Virtual Environments for Isolated and Reproducible Dependencies