Created
September 9, 2009 15:56
-
-
Save ttepasse/183838 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
class Base(object): | |
pass | |
class Eins(Base): | |
pass | |
class Zwei(Base): | |
pass | |
class WasAnderes(object): | |
pass | |
def subClassesOf(BaseClass, scope=None): | |
if not scope: | |
scope = globals() | |
map = {} | |
for name in scope: | |
obj = scope[name] | |
if ((type(obj) == type) and (issubclass(obj, BaseClass)) \ | |
and (obj is not BaseClass)): | |
map[name] = obj | |
return map | |
print subClassesOf(Base) | |
# {'Eins': <class '__main__.Eins'>, 'Zwei': <class '__main__.Zwei'>} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment