and tests of two other lister classes coming up the listinstance class we've coded so far works in any class it' mixed into because self refers to an instance of the subclass that pulls this class inwhatever that may be againin sensemix-in classes are the class equivalent of modules--packages of methods useful in variety of clients for examplehere is listinstance working again in single-inheritance mode on different class' instancesloaded with importand displaying attributes assigned outside the classimport listinstance class (listinstance listinstance)pass ( ax bx print( <instance of caddress = = = besides the utility they providemix-ins optimize code maintenancelike all classes do for exampleif you later decide to extend listinstance' __str__ to also print all the class attributes that an instance inheritsyou're safebecause it' an inherited methodchanging __str__ automatically updates the display of each subclass that imports the class and mixes it in and since it' now officially "later,let' move on to the next section to see what such an extension might look like listing inherited attributes with dir as it isour listerinstance mix-in displays instance attributes only ( names attached to the instance object itselfit' trivial to extend the class to display all the attributes accessible from an instancethough--both its own and those it inherits from its classes the trick is to use the dir built-in function instead of scanning the instance' __dict__ dictionarythe latter holds instance attributes onlybut the former also collects all inherited attributes in python and later the following mutation codes this schemei've coded this in its own module to facilitate simple testingbut if existing clients were to use this version instead they would pick up the new display automatically (and recall from that an import' as clause can rename new version to prior name being used)#!python file listinherited py ( xclass listinherited""use dir(to collect both instance attrs and names inherited from its classespython shows more names than because of the implied object superclass in the new-style class modelgetattr(multiple inheritance"mix-inclasses