As below, id(a.__getattribute__)
return different value when __getattr__
method defined. How did this happened? (My Python is v3.7.0)
class A():
def __getattribute__(self,key):
print(key)
return super().__getattribute__(key)
def f():
pass
def __getattr__(self,key):
print(key)
return super().__getattr__(key)
a=A()
print('id(a.__getattribute__)')
print(id(a.__getattribute__))
print(id(a.__getattribute__))
print(id(a.__getattribute__))
print(id(a.__getattribute__))
Output results:
id(a.__getattribute__)
__getattribute__
44147656
__getattribute__
12643664
__getattribute__
44147656
__getattribute__
12643664
When comment __getattr__
:
...
## def __getattr__(self,key):
## print(key)
## return super().__getattr__(key)
...
Output results:
id(a.__getattribute__)
__getattribute__
11005264
__getattribute__
11005264
__getattribute__
11005264
__getattribute__
11005264