Skip to content

Instantly share code, notes, and snippets.

@michaelosthege
Created March 7, 2017 22:04
Show Gist options
  • Save michaelosthege/2a857b9f5ac328196941b1de8dac1a76 to your computer and use it in GitHub Desktop.
Save michaelosthege/2a857b9f5ac328196941b1de8dac1a76 to your computer and use it in GitHub Desktop.
import python stuff from any directory
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