Elegant Solutions For Everyday Python Problems
summary
Shows concrete patterns: a Money class implements dunder add and on-the-fly currency conversion so adding $ and € just works; a Server becomes iterable with a generator to yield only active services; a tiny CLI uses getattr for dynamic commands; functools.partial makes base-2 int parsing ergonomic; a roughly 400-line REST client builds paths and returns 404s when appropriate; contextmanager/decorator examples (freezegun included) restore state reliably; namedtuple defaults and subclassing finish the toolbox.
AI-written summary · about
chapters (15)
- 0:00Intro
- 0:59slides
- 3:35Magic methods start and end with a double underscore (dunder)
- 6:16some magic methods map to symbols
- 6:38other magic methods map to built-in functions
- 7:13Making classes iterable
- 11:26Why does this work?
- 14:56Example: command line tool with dynamic commands
- 16:15Output
- 19:52define endpoint url & other connection properties
- 22:33Example Problem Feature Flags
- 24:04The better way: using the contextmanager decorator
- 27:47Problem: lost context using a decorator
- 28:05Decorators: Common uses
- 30:15Giving NamedTuples default values
related talks
46mOn Being Pythonic
32mPractical usage of advanced Python constructs
32mEasier Classes: Python Classes Without All the Cruft
01h 30mPython Design Patterns
30mAn Admin's Cornucopia - Python Is More Than Just A Better Bash
27mI love being Pythonic
22mEasier Classes: Python Classes Without All The Cruft
52mPython Tips, Tricks, and Idioms
