Skip to content

Instantly share code, notes, and snippets.

@andgineer
Created June 9, 2020 10:57
Show Gist options
  • Save andgineer/141f97164aaea12215cf9a2aed332c1d to your computer and use it in GitHub Desktop.
Save andgineer/141f97164aaea12215cf9a2aed332c1d to your computer and use it in GitHub Desktop.
Python: imports all symbols from all modules in the package
"""
Imports all symbols from all modules in the package
"""
from pathlib import Path
from importlib import import_module
for module_path in Path(__file__).parent.glob('*.py'):
if module_path.is_file() and not module_path.stem.startswith('_'):
module = import_module(f'.{module_path.stem}', package=__package__)
symbols = [symbol for symbol in module.__dict__ if not symbol.startswith("_")]
globals().update({symbol: getattr(module, symbol) for symbol in symbols})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment