Created
March 7, 2017 22:04
-
-
Save michaelosthege/2a857b9f5ac328196941b1de8dac1a76 to your computer and use it in GitHub Desktop.
import python stuff from any directory
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
def weirdimport(*paths): | |
import os, sys | |
fullpath = os.path.abspath(os.path.join(*paths)) | |
global project | |
sys.path.append(os.path.dirname(fullpath)) | |
try: | |
project = __import__(os.path.basename(fullpath)) | |
sys.modules['project'] = project | |
finally: | |
del sys.path[-1] | |
weirdimport(os.path.dirname(__file__), os.pardir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment