__getattr__ and __setattr__ Catch Attribute References : Getattr : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Getattr »

 

__getattr__ and __setattr__ Catch Attribute References


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

X = empty(  ) 
X.age



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Getattr