Skip to content

Instantly share code, notes, and snippets.

@0atman
Created December 19, 2012 15:07
Show Gist options
  • Save 0atman/4337330 to your computer and use it in GitHub Desktop.
Save 0atman/4337330 to your computer and use it in GitHub Desktop.
Finds all subclasses of `clazz` in `module`, returns a list.
def find_subclasses(module, clazz):
"""
Finds all subclasses of `clazz` in `module`, returns a list.
Source: http://stackoverflow.com/a/408465
"""
return [
cls for name, cls in inspect.getmembers(module)
if inspect.isclass(cls) and issubclass(cls, clazz)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment