__slots__in order to create an attribute namespace dictionary tooclass d__slots__ [' '' ''__dict__' def __init__(self)self ( attributeerrora name __dict__ to include one too class attrs work normally stored in __dict__a is slot all instance attrs undefined until assigned in this caseboth storage mechanisms are used this renders __dict__ too limited for code that wishes to treat slots as instance databut generic tools such as getattr still allow us to process both storage forms as single set of attributesx __dict__ some objects have both __dict__ and slot names {' ' getattr(can fetch either type of attr __slots__ [' '' ''__dict__'getattr( ' ')getattr( ' ')getattr( ' 'fetches all forms ( because dir also returns all inherited attributesthoughit might be too broad in some contextsit also includes class-level methodsand even all object defaults code that wishes to list just instance attributes may in principle still need to allow for both storage forms explicitly we might at first naively code this as followsfor attr in list( __dict__x __slots__print(attr'=>'getattr(xattr)wrong since either can be omittedwe may more correctly code this as followsusing get attr to allow for defaults-- noble but nonetheless inaccurate approachas the next section will explainfor attr in list(getattr( '__dict__'[])getattr( '__slots__'[])print(attr'=>'getattr(xattr) = = = __dict__ ={' ' less wrong multiple __slot__ lists in superclasses the preceding code works in this specific casebut in general it' not entirely accurate specificallythis code addresses only slot names in the lowest __slots__ attribute new-style class extensions