assignments to higher superclass to avoid loopingjust like __getattribute__ (and per the upcoming notethis scheme is sometimes preferred)def __setattr__(selfnamevalue)object __setattr__(self'other'valueforce higher to avoid me by contrastthoughwe cannot use the __dict__ trick to avoid loops in __getattri bute__def __getattribute__(selfname) self __dict__['other'loopsfetching the __dict__ attribute itself triggers __getattribute__ againcausing recursive loop strange but truethe __delattr__ method is less commonly used in practicebut when it isit is called for every attribute deletion (just as __setattr__ is called for every attribute assignmentwhen using this methodyou must take care to avoid loops when deleting attributesby using the same techniquesnamespace dictionaries operations or superclass method calls as noted 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 entirelybecause of thiscode that wishes to support such attributes should code __setattr__ to assign with the object __setattr__ scheme shown herenot by self __dict__ indexing namespace __dict__ operations suffice for classes known to store data in instanceslike this self-contained examplesgeneral toolsthoughshould prefer object first example generic attribute management is not nearly as complicated as the prior section may have implied to see how to put these ideas to workhere is the same first example we used for properties and descriptors in action againthis time implemented with attribute operator overloading methods because these methods are so genericwe test attribute names here to know when managed attribute is being accessedothers are allowed to pass normallyclass persondef __init__(selfname)self _name name def __getattr__(selfattr)print('getattrif attr ='name'return self _name elseportable or on [person()triggers __setattr__on [obj undefinedintercept namenot stored does not loopreal attr others are errors __getattr__ and __getattribute__