Skip to content

Instantly share code, notes, and snippets.

@poxip poxip/

Last active Aug 29, 2015
What would you like to do?
Loading a global module in Python3
import sys
from os import getcwd
from importlib import import_module
def import_global_module(name):
old_path = sys.path
except ValueError:
module = import_module(name)
sys.path = old_path
return module
yourmodule = import_global_module('yourmodule')
# print(yourmodule)
# bug found: If it's imported in other script, import_global_module will load local module
# (even if sys.path doesn't contain any local paths)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.