__dict__ as we dothoughkeep in mind that some programs may need to catch exceptions for missing __dict__or use hasattr to test or getattr with default if its users might deploy slots as we'll see in the next section' code won' fail if used by class with slots (its lack of them is enough to guarantee __dict__but slots--and other "virtualattributes--won' be reported as instance data generic display tool we can put these interfaces to work in superclass that displays accurate class names and formats all attributes of an instance of any class open new file in your text editor to code the following--it' newindependent module named classtools py that implements just such class because its __repr__ display overload uses generic introspection toolsit will work on any instanceregardless of the instance' attributes set and because this is classit automatically becomes general formatting toolthanks to inheritanceit can be mixed into any class that wishes to use its display format as an added bonusif we ever want to change how instances are displayed we need only change this classas every class that inherits its __repr__ will automatically pick up the new format when it' next runfile classtools py (new"assorted class utilities and toolsclass attrdisplay""provides an inheritable display overload method that shows instances with their class names and name=value pair for each attribute stored on the instance itself (but not attrs inherited from its classescan be mixed into any classand will work on any instance ""def gatherattrs(self)attrs [for key in sorted(self __dict__)attrs append('% =% (keygetattr(selfkey))return 'join(attrsdef __repr__(self)return '[% % ](self __class__ __name__self gatherattrs()if __name__ ='__main__'class toptest(attrdisplay)count def __init__(self)self attr toptest count self attr toptest count+ toptest count + more realistic example