Charles Krug wrote:
> The end result I'm after is an automatically generated dictionary
> containing instaces of the subclasses keyed by the subclass names:
>
> {'D':D(), 'E':E(), . . . }
>
> I can see the information I need in the module's __dict__ and by using
> the dir() method, but I'm not having much success extracting it.
Try this:
class C(object): pass
class D(C): pass
class E(C): pass
def CSubclasses():
return dict((cls.__name__, cls) for cls in C.__subclasses__())
print CSubclasses()
--
http://mail.python.org/mailman/listinfo/python-list