Python - How to Import a Module Outside of sys.path

For those times when appending to sys.path is out of the question, the imp module exposes functions from Python's import module.

import imp
myModule = imp.load_source("myModule", "a:\path\that\is\not\in\the\syspath\myFile.py")

In my case, I was using it in a destination module to control a tool distribution system, and I didn't want to import both source and destination mirrored modules but still wanted to access one particular file.

No comments:

Post a Comment