PYTHON EXPERTChapter 11 · Python Expert
Dynamic properties and descriptors
Python lets you customize attribute access using metaprogramming. Override __getattr__ to intercept missing attributes, __setattr__ for writes, and use property descriptors to manage class variables.
Worked example
How it reads
- __getattr__(self, name) runs only when the attribute does not exist
- It returns a computed value dynamically

Cloud tip: Use __getattr__ for fallback lookup; use __getattribute__ to intercept every attribute access (but watch out for infinite recursion).


