strings herein keeping with ' factories pattern ""import importlib def tester(listerclasssept=false)class superdef __init__(self)self data 'spamdef ham(self)pass superclass __init__ create instance attrs class sub(superlisterclass)def __init__(self)super __init__(selfself data 'eggsself data def spam(self)pass mix in ham and __str__ listers have access to self instance sub(print(instanceif septprint('- return instance with lister' __str__ run mixed-in __str__ (or via str( )more instance attrs define another method here def testbynames(modnameclassnamesept=false)modobject importlib import_module(modnameimport by namestring listerclass getattr(modobjectclassnamefetch attr by namestring tester(listerclassseptif __name__ ='__main__'testbynames('listinstance''listinstance'truetestbynames('listinherited''listinherited'truetestbynames('listtree''listtree'falsetest all three here while it' at itthis script also adds the ability to specify test module and class by name stringand leverages this in its self-test code--an application of the factory pattern' mechanics described earlier here is the new script in actionbeing run by the lister module that imports it to test its own class (with the same results in and again)we can run the test script itself toobut that mode tests the two lister variantswhich we have yet to see (or code!) :\codepython listinstance py <instance of subaddress data =spam data =eggs data = :\codepython testmixin py <instance of subaddress data =spam data =eggs data = designing with classes