__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


Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0