table attribute access special methods special method usage __delattr__(selfnamedel deletes object ' attribute __dir__(selfdir(x__getattr__(selfname__getattribute__(selfnamedescription returns list of ' attribute names returns the value of object ' attribute if it isn' found directly returns the value of object ' attributesee text __setattr__(selfnamevaluex sets object ' attribute' value to the name of the nonexistent attribute the class works because we are using the object' __dict__ which is what the base class __getattr__()__setattr__()and __delattr__(methods usealthough here we have used only the base class' __getattr__(method all the special methods used for attribute access are listed in table there is another way of getting constantswe can use named tuples here are couple of examplesconst collections namedtuple(" ""min max")( const minconst max returns( offset collections namedtuple(" ""id name description")(*range( )offset idoffset nameoffset description returns( in both cases we have just used throwaway name for the named tuple because we want just one named tuple instance each timenot tuple subclass for creating instances of named tuple although python does not support an enum data typewe can use named tuples as we have done here to get similar effect image py for our last look at attribute access special methods we will return to an example we first saw in in that we created an image class whose widthheightand background color are fixed when an image is created (although they are changed if an image is loadedwe provided access to them using read-only properties for examplewe had@property def width(self)return self __width this is easy to code but could become tedious if there are lot of read-only properties here is different solution that handles all the image class' read-only properties in single method