I have already seen the following question, but this is not entirely clear to me: How can I get a list of all classes in the current module in Python?
In particular, I do not want to import classes, for example. 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) , as the accepted answer suggests in a related question, it will return MyBaseClass and SomeOtherClass in addition to the 3 defined in this module.
How can I get only NewClass , AnotherClass and YetAnotherClass ?
Davy8 Apr 02 2018-11-11T00: 00Z
source share