Finding all classes in a module

Hans Nowak wurmy at
Fri Aug 9 21:04:03 CEST 2002

Tom Harris wrote:
> If I import a module, how do I find the names of the class objects it
> contains?

The replies you got so far only seem to work for old-style classes:

 >>> import types
 >>> class D(dict): pass

 >>> isinstance(D, types.ClassType)

I think this should work for new-style classes, though:

 >>> isinstance(D, type)

So, to find both types of classes, do something like

   if isinstance(obj, types.ClassType) or isinstance(obj, type):


Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter::

More information about the Python-list mailing list