What is `__getattr__` vs `__getattribute__` in Python attribute lookup?

Python Developer Hard

Python Developer — Hard

What is `__getattr__` vs `__getattribute__` in Python attribute lookup?

Key points

  • __getattribute__ is called on every attribute access
  • __getattr__ is called only when normal lookup fails
  • Overriding __getattribute__ can intercept all access but requires calling super() carefully

Ready to go further?

Related questions