Finding all classes in a module

Mark McEahern marklists at mceahern.com
Fri Aug 9 21:11:22 CEST 2002


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

[snip]

Good point.  Here's another approach:

  # junk.py
  class foo:pass
  class bar(object):pass

Then:

  >>> import junk
  >>> import inspect
  >>> inspect.getmembers(junk, inspect.isclass)
  [('bar', <class 'junk.bar'>), ('foo', <class junk.foo at 0x10102d28>)]

and so.

// mark
-





More information about the Python-list mailing list