dictionary works to avoid repeats in the output because class objects are hashable and thus may be dictionary keysa set would provide similar functionality technicallycycles are not generally possible in class inheritance trees-- class must already have been defined to be named as superclassand python raises an exception as it should if you attempt to create cycle later by __bases__ changes--but the visited mechanism here avoids relisting class twiceclass cpass class ( )pass __bases__ ( ,deepdark magictypeerrora __bases__ item causes an inheritance cycle usage variationshowing underscore name values this version also takes care to avoid displaying large internal objects by skipping __x__ names again if you comment out the code that treats these names speciallyfor attr in sorted(obj __dict__)if attr startswith('__'and attr endswith('__')result +spaces '{ }\nformat(attrelseresult +spaces '{ }={ }\nformat(attrgetattr(objattr)then their values will display normally here' the output in with this temporary change madegiving the values of every attribute in the class treec:\codec:\python \python listtree py <instance of subaddress _listtree__visited={data =spam data =eggs data = <class subaddress __doc__=none __init____module__=testmixin spam<class superaddress __doc__=none __init____module__=testmixin ham<class listtreeaddress _listtree__attrnames_listtree__listclass__doc__mix-in that returns an __str__ trace of the entire class tree and all its objectsattrs at and above selfrun by print()str(returns multiple inheritance"mix-inclasses