Wangling I'm Wang Ling. I'm wangling you.

Posts Tagged ‘Python’

Attribute Access Machinery of New Style Objects/Classes

Attribute access of form obj.d triggers the special method type(obj).__getattribute__ to be invoked. Thus, for objects, it is object.__getattribute__ that defines the general machinery of attribute access. The implementation in python code is as follows: def __getattribute__(obj, name): cls = type(obj) class_attr = class_lookup(cls, name) # data descriptor if class_attr and is_data_desc(class_attr): return class_attr.__get__(obj, cls) [...]