classes and object-oriented programming that casethe set and delete operation will be carried out by the set and delete functions associated with the property for attribute lookup such as obj namethe special method obj _getattrribute_ ("name"is invoked this method carries out the search process for finding the attributewhich normally includes checking for propertieslooking in the local _dict_ attributechecking the class dictionaryand searching the base classes if this search process failsa final attempt to find the attribute is made by trying to invoke the _getattr_ (method of the class (if definedif this failsan attributeerror exception is raised user-defined classes can implement their own versions of the attribute access functionsif desired for exampleclass circle(object)def _init_ (self,radius)self radius radius def _getattr_ (self,name)if name ='area'return math pi*self radius** elif name ='perimeter'return *math pi*self radius elsereturn object _getattr_ (self,namedef _setattr_ (self,name,value)if name in ['area','perimeter']raise typeerror("% is readonlynameobject _setattr_ (self,name,valuea class that reimplements these methods should probably rely upon the default implementation in object to carry out the actual work this is because the default implementation takes care of the more advanced features of classes such as descriptors and properties as general ruleit is relatively uncommon for classes to redefine the attribute access operators howeverone application where they are often used is in writing generalpurpose wrappers and proxies to existing objects by redefining _getattr_ () _setattr_ ()and _delattr_ () proxy can capture attribute access and transparently forward those operations on to another object _slots_ class can restrict the set of legal instance attribute names by defining special variable called _slots_ here' an exampleclass account(object) _slots_ ('name','balance'when _slots_ is definedthe attribute names that can be assigned on instances are restricted to the names specified otherwisean attributeerror exception is raised this restriction prevents someone from adding new attributes to existing instances and solves the problem that arises if someone assigns value to an attribute that they can' spell correctly in reality_ _slots_ was never implemented to be safety feature insteadit is actually performance optimization for both memory and execution speed instances of class that uses _slots_ no longer use dictionary for storing instance data insteada much more compact data structure based on an array is used in programs that lib fl ff