What is the purpose of __getattr__ versus __getattribute__ in Python?

Python Professional Hard

Python Professional — Hard

What is the purpose of __getattr__ versus __getattribute__ in Python?

Key points

  • __getattribute__ is always invoked, while __getattr__ is a fallback.
  • __getattribute__ is more general, while __getattr__ is specific to missing attributes.
  • Understanding the difference between these methods is crucial for custom attribute handling in Python.

Ready to go further?

Related questions