Created
April 24, 2013 07:48
-
-
Save K240-zz/5450389 to your computer and use it in GitHub Desktop.
Import from any path
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