What is the difference between __getattr__ and __getattribute__?

Python advanced features · Experienced

Model answer

__getattribute__ is called for every attribute access. __getattr__ is only called when normal lookup fails. Overriding __getattribute__ is risky, since it is easy to cause infinite recursion, so use __getattr__ for fallback behaviour.

Learn this topic

The Python Standard Library: Dates, Counter, Statistics and More in the course Python for Beginners: Learn to Code with Real Projects.

Sign in to add your own answer.

More questions