Created
February 2, 2017 14:16
-
-
Save mdellavo/e032a9da68aeddef0e9f8fb33880cbe2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import inspect | |
import pkgutil | |
import importlib | |
def find_subsclasses(package, baseclass): | |
for importer, modname, ispkg in pkgutil.iter_modules(package.__path__): | |
if ispkg: | |
continue | |
module = importlib.import_module(package.__name__ + "." + modname, package.__name__) | |
for name in dir(module): | |
obj = getattr(module, name) | |
if inspect.isclass(obj) and issubclass(obj, baseclass): | |
yield obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment