2
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?

David Robinson
  • 77,383
  • 16
  • 167
  • 187

3 Answers3

7

You can use inspect:

import myModule

import inspect    
print inspect.getmembers(myModule, inspect.isclass)
Jochen Ritzel
  • 104,512
  • 31
  • 200
  • 194
0

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

theodox
  • 12,028
  • 3
  • 23
  • 36
0

May be you can use locale() function with filtering.

Mirat Can Bayrak
  • 631
  • 7
  • 18