We can call an attribute directly through object.attribute
, but I guess there are cases that they are called implicit. The code below shows what i believe it's happening:
class Test():
list=[0,1]
def __init__(self,age):
print("before __getattribute__")
self.list[0]=1
print("after __getattribute__")
def __getattribute__(self,attribute):
print("Initializing getattribute")
return object.__getattribute__(self,attribute)
def __setattr__(self,attribute,value):
print("Calling setattr")
test=Test(4)
The output is:
before __getattribute__
Initializing getattribute
after __getattribute__
So self.list[0]=1
is calling an attribute, since its invoking the __getatrtibute__
.
What are other cases that this may happen?