Last active
August 20, 2023 22:26
-
-
Save AkazaRenn/6298f3c1bccd3fa73b45ba496b70c886 to your computer and use it in GitHub Desktop.
Asterisk import all files in this folder (breaks syntax highlighing)
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
import importlib.util | |
# Import all regular *.py files in this folder | |
# From https://stackoverflow.com/a/57892961 | |
for module_path in current_dir.glob('*.py'): | |
module_name = module_path.stem | |
if module_name.startswith('__'): | |
continue | |
module_spec = importlib.util.spec_from_file_location(module_name, module_path) | |
module = importlib.util.module_from_spec(module_spec) | |
module_spec.loader.exec_module(module) | |
# Equivalent to: from module import * | |
for obj in dir(module): | |
globals()[obj] = module.__dict__[obj] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment