Created
June 9, 2020 10:57
-
-
Save andgineer/141f97164aaea12215cf9a2aed332c1d to your computer and use it in GitHub Desktop.
Python: imports all symbols from all modules in the package
This file contains 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
""" | |
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