What is the difference between __getattr__ and __getattribute__?
PICTURE THIS: RAG CHATBOT
Simple meaning
__getattribute__ runs on every attribute access and is easy to recurse infinitely if you are not careful
WHY — Dunder Methods instead of guessing?
Why interviewers care about Dunder Methods:
contrast on Dunder Methods, not two memorised paragraphs.
the developer, then one case where picking wrong hurts.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1__getattribute__ runs on every
attribute access and is easy to recurse infinitely if you are not careful
- 2use object.__getattribute__ or super()
for internals.
- 3__getattr__ runs only after
normal lookup fails, which is the usual hook for lazy attributes.
- 4Django's RelatedManager uses descriptor
machinery rather than __getattr__ for FK access.
- 5Common mistake
What juniors usually get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
__getattribute__ runs on every attribute access and is easy to recurse infinitely if you are not careful use object.__getattribute__ or super() for internals.