At Monday 15/1/2007 04:27, you wrote:
I want to get all classes of a module in a list. I wrote this code but I
wonder
if there's not a simpler solution
import inspect
def getClassList(aModule):
return [getattr(aModule, attName) \
for attName in aModule.__dict__ \
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,
Looks rather simple to me... Anyway, you could avoid calling getattr
twice, if you iterate over vars(aModule).itervalues()
def getClassList(aModule):
return [cls for cls in vars(aModule).itervalues()
if inspect.isclass(cls)]
(And note that there is no need for using \ at the line
[EMAIL PROTECTED] 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:
Hi,
I want to get all classes of a module in a list. I wrote this code but I
wonder
if there's not a simpler solution
import inspect
def getClassList(aModule):
return [getattr(aModule, attName) \
for attName in aModule.__dict__ \
if