python - How do you get all classes defined in a module but not imported? -
i've seen following question doesn't quite me want: how can list of classes within current module in python?
in particular, not want classes imported, e.g. if had following module:
from my.namespace import mybaseclass somewhere.else import someotherclass class newclass(mybaseclass): pass class anotherclass(mybaseclass): pass class yetanotherclass(mybaseclass): pass
if use clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass)
accepted answer in linked question suggests, return mybaseclass
, someotherclass
in addition 3 defined in module.
how can newclass
, anotherclass
, yetanotherclass
?
inspect __module__
attribute of class find out module defined in.
Comments
Post a Comment