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
  • 74,512
  • 15
  • 159
  • 179

3 Answers3

7

You can use inspect:

import myModule

import inspect    
print inspect.getmembers(myModule, inspect.isclass)
Jochen Ritzel
  • 99,912
  • 29
  • 194
  • 188
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
  • 11,783
  • 3
  • 21
  • 36
0

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

Mirat Can Bayrak
  • 621
  • 7
  • 18