Seven Things Every Python Programmer Should Know
summary
Explains seven concrete pitfalls and fixes: default empty lists are created once at import and persist across calls causing state bugs; fix with an immutable tuple or a unset = object() sentinel and runtime list creation. Clarifies namespaces and the LEGB lookup (no C for class scope). Shows that exact geometry with fractions (45× slower) removes float pathology. Demonstrates profiling with cProfile and disassembly to find costly attribute-dictionary lookups, and replacing hot Python (IBM-float conversion for seg-y) with C++ yields an 86% speedup.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 2:49Code Execution
- 5:06Empty Lists
- 10:30Sentinel Objects
- 23:18No tradeoffs
- 23:33Floatingpoint arithmetic
- 24:14Number types
- 25:02Decimal and fractions
- 25:18Failure modes of float
- 25:49Floats are binary
- 27:23Decimals are floatingpoints
- 28:42Computational geometry
- 29:41Sign of the determinant
- 30:12Demonstration
- 33:20Floating point numbers
- 34:13Python quirks
- 38:18Python idioms
- 40:32Chain comparisons
- 44:26Reduce work
related talks
46mOn Being Pythonic
01h 18mPython 103: Mmmm... Understanding Python's Memory Model, Mutability, and Methods
27mVariables and objects in Python: it's pointers all the way down
01h 18mPython 103: Mmmm... Understanding Python's Memory Model, Mutability, and Methods
52mPython Tips, Tricks, and Idioms
30mWrite faster Python! Common performance anti patterns
27mPython Oddities Explained
24mPython for Humans, Designing Python Code Like a User Interface
