Import from database
steve at holdenweb.com
Tue Jan 25 12:54:40 EST 2005
> I believe you have to put ntpath, macpath and posixpath in the module
> database for os.path to work.
> I tried it with zipimporter builtin and I got the same traceback till I
> added ntpath.py to my zip file. (Of course, I renamed the original
> ntpath to _ntpath so that the original did not get imported)
I'm not sure I understand, as I am currently relying on the system
implementations of any modules that happen to be loaded before my code
picks up. As to what's in the database
WHERE modName LIKE '%path%'
shows that I have macpathm macurlpath, ntpath, nturlpath, os2emxpath and
posixpath all there (but, as I say, I've already executed the standard
modules by the time anything of mine gets to run). If I alter my test
import dbimp, sys
if __name__ == "__main__":
k = sys.modules.keys()
for kk in k:
then I get as output
found a in db
a loaded: <module 'a' from 'db:a'> pkg: 1
found a.b in db
a.b loaded: <module 'a.b' from 'db:a.b'> pkg: 1
found a.b.c in db
a.b.c loaded: <module 'a.b.c' from 'db:a.b.c'> pkg: 1
found a.b.c.d in db
a.b.c.d loaded: <module 'a.b.c.d' from 'db:a.b.c.d'> pkg: 0
found bsddb in db
found weakref in db
weakref loaded: <module 'weakref' from 'db:weakref'> pkg: 0
Traceback (most recent call last):
File "test.py", line 11, in ?
File "/c/steve/Projects/Python/dbimp/dbimp.py", line 49, in load_module
exec code in module.__dict__
File "db:bsddb", line 62, in ?
File "/usr/lib/python2.4/os.py", line 133, in ?
from os.path import (curdir, pardir, sep, pathsep, defpath, extsep,
ImportError: No module named path
In other words, the os module is /already/ in sys.smodules, as is
os.path, yet the interpreter is complaining (I presume) that os.path is
not a module. I don't even know *why* os is being executed a second
time. I can only assume it's being imported as some other name like
"bsddb.os" and some element of the import system is actually doing an
import rather than refusing to guess.
I presume I need to control the import process more closely to make sure
that this import attempt is rejected, but I can't see how to do that.
More information about the Python-list