Class list of a module

George Sakkis george.sakkis at gmail.com
Tue Jan 16 03:36:25 CET 2007


bearophileHUGS at lycos.com wrote:

> Gabriel Genellina:
> > >import inspect
> > def getClassList(aModule):
> >      return [cls for cls in vars(aModule).itervalues()
> >                      if inspect.isclass(cls)]
>
> This is short enough too:
>
> from inspect import isclass
> getclasses = lambda module: filter(isclass, vars(module).itervalues())
>
> Bye,
> bearophile

Or even:

from inspect import getmembers, isclass
def getclasses(module):
    return [cls for name,cls in getmembers(module,isclass)]

George




More information about the Python-list mailing list