__setattr__ and __dict__ : Class setattr : Class PYTHON examples


PYTHON examples » Class » Class setattr »

 

__setattr__ and __dict__


__setattr__ and __dict__

class accesscontrol:
     def __setattr__(self, attr, value):
         if attr == 'age':
             self.__dict__[attr= value
         else:
             raise AttributeError, attr + ' not allowed'

X = accesscontrol()
X.age = 40                     # calls __setattr__
print X.age

X.name = 'mel'

print X.name

           
       



    Related Scripts with Example Source Code in same category :

Leave a Comment / Note


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


PYTHON examples

 Navioo Class
» Class setattr