Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os.path.join(path1,path2,filename) import *
- from importlib import import_module
- module = importmodule('.'.join([path1, path2, filename[:-3]])
- for attr in dir(module):
- globals()[attr] = getattr(module, attr)
- namespace = {}
- for attr in dir(module):
- namespace[attr] = getattr(module, attr)
- def import_path(path1, path2, module_name, namespace=None):
- import sys
- from importlib import import_module
- from pathlib import Path # new code should use this instead of "os.path" stuff
- path = Path(path1).joinpath(path2)
- name = module_name[-3:] if module_name.endswith(".py") else module_name
- try:
- sys.path.insert(0, str(path))
- module = import_module(name)
- finally:
- sys.path.remove(str(path))
- if namespace is None:
- namespace = sys._getframe().f_back.f_globals()
- for name in dir(module):
- namespace[name] = getattr(module, name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement