In Python, classes can intercept basic attribute access.
class Empty: def __getattr__(self, attrname): # On self.undefined if attrname == 'age': return 40 else: # from w w w . jav a 2 s . c om raise AttributeError(attrname) X = Empty() print( X.age ) print( X.name )
Here, the Empty class and its instance X have no real attributes of their own.
The access to X.age gets routed to the __getattr__ method.
The class makes age look like a real attribute by returning a real value.