mm.py
class A():
def __init__(self):
pass
class B():
def __int__(slef):
pass
How can I generate a list of all the classes in mm.py?
mm.py
class A():
def __init__(self):
pass
class B():
def __int__(slef):
pass
How can I generate a list of all the classes in mm.py?
You can use inspect
:
import myModule
import inspect
print inspect.getmembers(myModule, inspect.isclass)
You can import the module and scan all the names in it using dir (module):
import mymodule
import types
for item in dir(mymodule):
itemtype = type(item)
if itemtype == types.ClassType:
print item + "is old style class"
if itemtype == types.TypeType:
print item + "is new style class"
Updated for old and new style classes