I have a list of strings, which all are modules that are imported (I parsed the __init__.py file earlier for some other validation). For example mods = ['mod_one', 'mod_two', 'mod_three']. I now need to verify that all of these are an instance of a pre-defined superclass (skeleton.py) - like
for x in mods:
if not isinstance(x.Operation,skeleton.OperationSkeleton):
print("error with: "+x)`
My problem is that x is in this case a string - obviously, but is the name of the imported module I want to check. The string doesn't have a Operation..
And odd enough.. for testing purpose did I try to
print(isinstance(mod_one.Operation,skeleton.OperationSkeleton))
and it prints False.
But in mod_one.py the OperationSkeleton is imported from skeleton and class Clustering(ClusteringSkeleton): is created.
class Clusteringis not the same thing asclass.Operation.OperationSkeletonis imported fromskeletonandclass Operation(OperationSkeleton):is created.isinstance()would just work. But do make sure you didn't accidentally added a package subdirectory to your path and imported the module under two different names (package.moduleandmodule), for example. You can verify you have the same class by looking at theid(skeleton.OperationSkeleton)and also look atskeleton.__name__andskeleton.OperationSkeleton.__module__in both locations.