__getattr__ demo : Class getattr « Class « Python






__getattr__ demo

__getattr__ demo

class empty:
     def __getattr__(self, attrname):
         if attrname == "age":
             return 41
         else:
             raise AttributeError, attrname

X = empty()
print X.age

           
       








Related examples in the same category

1.__getattr__ in a class Demo