I've already seen the following question but it doesn't quite get me where I want: How can I get a list of all classes within current module in Python?
In particular, I do not want classes that are imported, e.g. if I had the following module:
from my.namespace import MyBaseClass
from somewhere.else import SomeOtherClass
class NewClass(MyBaseClass):
pass
class AnotherClass(MyBaseClass):
pass
class YetAnotherClass(MyBaseClass):
pass
If I use clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass)
like the accepted answer in the linked question suggests, it would return MyBaseClass
and SomeOtherClass
in addition to the 3 defined in this module.
How can I get only NewClass
, AnotherClass
and YetAnotherClass
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…