Class list of a module
George Sakkis
george.sakkis at gmail.com
Mon Jan 15 21:36:25 EST 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