Skip to content

Instantly share code, notes, and snippets.

@winniehell
Created January 5, 2015 18:38
Show Gist options
  • Save winniehell/d7598ebddb51a6c504a2 to your computer and use it in GitHub Desktop.
Save winniehell/d7598ebddb51a6c504a2 to your computer and use it in GitHub Desktop.
Find all python classes within the current package
import importlib
import inspect
import pkgutil
package = importlib.import_module(__package__)
for loader, module_name, is_pkg in pkgutil.iter_modules(package.__path__):
if not is_pkg:
module = importlib.import_module(__package__+'.'+module_name)
for name, obj in inspect.getmembers(module):
if inspect.isclass(obj):
print(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment