def __setattr__(selfattrvalue)if attr ='age'self __dict__[attrvalue not self name=val or setattr elseraise attributeerror(attr not allowed' accesscontrol( age age name 'bobtext omitted attributeerrorname not allowed calls __setattr__ if you change the __dict__ assignment in this to either of the followingit triggers the infinite recursion loop and exception--both dot notation and its setattr built-in function equivalent (the assignment analog of getattrfail when age is assigned outside the classself age value setattr(selfattrvalue loops loops (attr is 'age'an assignment to another name within the class triggers recursive __setattr__ call toothough in this class ends less dramatically in the manual attributeerror exceptionself other recurs but doesn' loopfails it' also possible to avoid recursive loops in class that uses __setattr__ by routing any attribute assignments to higher superclass with callinstead of assigning keys in __dict__self __dict__[attrvalue object __setattr__(selfattrvalue okdoesn' loop okdoesn' loop (new-style onlybecause the object form requires use of new-style classes in xthoughwe'll postpone details on this form until ' deeper look at attribute management at large third attribute management method__delattr__is passed the attribute name string and invoked on all attribute deletions ( del object attrlike __setattr__it must avoid recursive loops by routing attribute deletions with the using class through __dict__ or superclass as we'll learn in attributes implemented with new-style class features such as slots and properties are not physically stored in the instance' __dict__ namespace dictionary (and slots may even preclude its existence entirely!because of thiscode that wishes to support such attributes should code __setattr__ to assign with the object __setattr__ scheme shown herenot by self __dict__ indexing unless it' known that subject classes store all their data in the instance itself in we'll also see that the new-style __getattribute__ attribute access__getattr__ and __setattr__