Skip to content

Instantly share code, notes, and snippets.

@fereria
Created April 14, 2019 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/822d9c254687b8dbde08512812d5f4ea to your computer and use it in GitHub Desktop.
Save fereria/822d9c254687b8dbde08512812d5f4ea to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import glob
import sys
import os.path
import importlib
import re
this_file = os.path.dirname(os.path.abspath(__file__))
def load_module():
myself = sys.modules[__name__]
mod_paths = glob.glob(os.path.join(this_file, '*.py'))
for py_file in mod_paths:
mod_name = os.path.splitext(os.path.basename(py_file))[0]
if re.search(".*__init__.*", mod_name) is None:
mod = importlib.import_module(__name__ + "." + mod_name)
for m in mod.__dict__.keys():
if not m in ['__builtins__', '__doc__', '__file__', '__name__', '__package__']:
myself.__dict__[m] = mod.__dict__[m]
load_module()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment