Skip to content

Instantly share code, notes, and snippets.

@ttepasse
Created September 9, 2009 15:56
Show Gist options
  • Save ttepasse/183838 to your computer and use it in GitHub Desktop.
Save ttepasse/183838 to your computer and use it in GitHub Desktop.
#!/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