get a list of classes in this module

Mark McEahern marklists at mceahern.com
Wed Jun 12 23:19:19 CEST 2002


[Terry Reedy]
> I believe the name of a modulue is the same inside as out.  I do not
> know inspect or whether it can work on a module under construction.
> However, if the subclasses are too numerous to build the dict by hand,
> or the set so dynamic that you do not trust yourself to update it
> properly...

Yeah, it's not so much that I don't trust myself--there's that.  ;-)  But
it's also the simple DRY principle at work.  Why should I have to list the
classes in that factory-like dictionary when Python can do that for me?

Thankfully, I didn't have to resort to globals()--but took advantage of
Python 2.2's __subclasses__ (which requires subclassing the base class from
object).  That worked smoov.

Thanks,

// mark

-






More information about the Python-list mailing list