Created
December 5, 2012 12:03
-
-
Save dyng/4215016 to your computer and use it in GitHub Desktop.
通过绝对路径import模块
This file contains hidden or 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 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