I’m trying to access attributes of member functions, but I cannot understand why I can access only through the __dict__.
class A(object):
def fA(self):
print A.fA.x
fA.x = 2
A.fA.__dict__['x'] = 3
#A.fa.x #AttributeError: 'instancemethod' object has no attribute 'x'
A.fA.x = 4
Why I do get an AttributeError if I try to access ‘directly’?
Because of how
instancemethodobjects are implemented. They use a non-standard attribute-getter which doesn’t allow access to non-standard attributes.