Skip to content

Instantly share code, notes, and snippets.

@AkazaRenn
Last active August 20, 2023 22:26
Show Gist options
  • Save AkazaRenn/6298f3c1bccd3fa73b45ba496b70c886 to your computer and use it in GitHub Desktop.
Save AkazaRenn/6298f3c1bccd3fa73b45ba496b70c886 to your computer and use it in GitHub Desktop.
Asterisk import all files in this folder (breaks syntax highlighing)
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