Skip to content

Instantly share code, notes, and snippets.

@K240-zz
Created April 24, 2013 07:48
Show Gist options
  • Select an option

  • Save K240-zz/5450389 to your computer and use it in GitHub Desktop.

Select an option

Save K240-zz/5450389 to your computer and use it in GitHub Desktop.
Import from any path
def import_path(fullpath):
"""
Import a file with full path specification. Allows one to
import from anywhere, something __import__ does not do.
"""
path, filename = os.path.split(fullpath)
filename, ext = os.path.splitext(filename)
sys.path.append(path)
module = __import__(filename)
reload(module) # Might be out of date
del sys.path[-1]
return module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment