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__ \
if inspect.isclass(getattr(aModule, attName))]
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 ends, because
of the [])
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
--
http://mail.python.org/mailman/listinfo/python-list