dynamic - python load module from built-in -
i'm using python 3, , have module named "http" (mypackage.http), , have module called foo, want load built-in http module (not mypackage.http module)
i can use
imp.find_module('http', sys.path[1:])   for built-in __ init__.py importlib path
example:
/usr/local/cellar/python3/3.3.2/frameworks/python.framework/versions/3.3/lib/python3.3/importlib/__ init__.py
but use of imp.find_module()/load_module() deprecated.
how can import built-in http module way importlib?
project example:
- mypackage 
- _init _.py
 - http.py (has related http classes, etc)
 - foo.py (needs use built-in http , not mypackage.http)
 
 
thanks!
just use
import http   in python 2, wouldn't have worked if foo in mypackage, relative imports need explicit in python 3.
if you're running module script, you'll need fix path somehow. if mypackage findable using normal import mechanisms, can run module -m switch:
python -m mypackage.foo   otherwise, may need check path , alter manually, setting __package__ relative imports work right.
Comments
Post a Comment