A python script with a filename that you wouldn't normally be able to import,
For example, zz-myscript-01.py
I want to import a function implemented inside such a guy.
But,
import zz-myscript-01
Cannot be written like (Syntax Error)
I want to load it without changing the name.
Use `ʻimp. For example, to load the above script with the name
mymodule``
OK if you do the following.
def customImport():
import imp
global mymodule
fp, name, desc = imp.find_module("zz-myscript-01")
mymodule = imp.load_module("mymodule", fp, name, desc)
customImport()
Because `ʻimp`` is an interface to the Python import statement implementation, Because I use it to import my own.
http://docs.python.jp/2/library/imp.html#examples-imp
Recommended Posts