list classes in package

Diez B. Roggisch deets at nospam.web.de
Wed Jan 16 10:36:36 EST 2008


Dmitry wrote:

> Hi All,
> 
> I've trying to develop one Python application, and
> neet to solve one problem. I need to list all classes defined in one
> package (not module!).
> 
> Could anybody please show me more convinient (correct) way to
> implement this?

Look at the module inspect and it's predicates. Something like


for name in dir(module_or_package):
    if inspect.isclass(getattr(module_or_package, name)):
       print "%s is a class" % name


Diez



More information about the Python-list mailing list