I am trying to understand when to use __getattr__
or __getattribute__
. The documentation mentions __getattribute__
applies to new-sty
I find that no one mentions this difference:
__getattribute__
has a default implementation, but __getattr__
does not.
class A:
pass
a = A()
a.__getattr__ # error
a.__getattribute__ # return a method-wrapper
This has a clear meaning: since __getattribute__
has a default implementation, while __getattr__
not, clearly python encourages users to implement __getattr__
.