C
Charles Krug
List:
I have this:
# classC.py
class C(object): pass
class D(C): pass
class E(C): pass
def CSubclasses():
for name in dir(): pass
I'm trying to create a list of all of C's subclasses:
import classC
print C
aList = []
for name in dir(classC):
print name,
try:
if issubclass(classC.__dict__[name], C):
print classC.__dict__[name]
else:
print
except TypeError:
print
Which gives me this:
<class '__main__.C'>
C
CSubclasses
D
E
__builtins__
__doc__
__file__
__name__
However when I do this from the command line:
So my approach is flawed.
The end result I'm after is an automatically generated dictionary
containing instaces of the subclasses keyed by the subclass names:
{'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.
I have this:
# classC.py
class C(object): pass
class D(C): pass
class E(C): pass
def CSubclasses():
for name in dir(): pass
I'm trying to create a list of all of C's subclasses:
import classC
print C
aList = []
for name in dir(classC):
print name,
try:
if issubclass(classC.__dict__[name], C):
print classC.__dict__[name]
else:
except TypeError:
Which gives me this:
<class '__main__.C'>
C
CSubclasses
D
E
__builtins__
__doc__
__file__
__name__
However when I do this from the command line:
False
So my approach is flawed.
The end result I'm after is an automatically generated dictionary
containing instaces of the subclasses keyed by the subclass names:
{'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.