Suppose a class A
is defined as:
class A:
def __init__(self, val):
self.val = val
After A
is instantiated by a = A(3)
, what methods will be called by executing a.val
? In other words, what will happen internally when a.val
is executed?
Moreover, how about A
accessing a non-existed attribute, namely other_val
, by executing A.other_val
?
I heard about built-in methods such as getattr
and setattr
, and class protocol method __getattr__
, __setattr__
and __getattribute__
, which of them and how they are triggered when A.*
is executed?
I only found few documentations on this, so any materials that explains the problem will help. Thanks in advance.