Skip to content
dreamcode
dreamcode
Back to map
Metaprogramming · Lesson 32 of 44
+15 XP on finish
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.

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).
main.py
PYTHON
real Python, runs in your browser
CONSOLE
- run your code to see output -