I read a little search for the python object attribute (here: https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/#object-attribute-lookup ).
It seems pretty straight forward, so I tried (python3):
class A: def __getattr__(self, attr): return (1,2,3) a = A() a.foobar
My question is not that both should be the same?
Why does the second cause an attribute error?
Therefore, the answer seems to be that the logic for a.foobar IS is different from the logic for a.__getattribute("foobar") . According to the data model : a.foobar calls a.__getattribute("foobar") , and if it calls the AttributeError attribute, it calls a.-__getattr__('foobar')
So it seems that the article is wrong in its diagram. Is it correct?
And one more question: where is the real logic for a.foobar sitting? I thought it was in __getattribute__ , but apparently not completely.
Edit: Not a duplicate
The difference between __getattr__ vs __getattribute__ . I ask what is the difference between object.foo and object.__getattribute__("foo") . This is different from __getattr__ vs __getatribute__ , which is trivial ...
source share