Hey, get this! [was: import from database]
Peter Otten
__peter__ at web.de
Fri Jan 28 10:31:52 EST 2005
Steve Holden wrote:
> This is even stranger: it makes it if I import the module a second time:
[second import seems to succeed]
Maybe you are experiencing some version confusion? What you describe looks
much like the normal Python 2.3 behaviour (with no import hook involved)
whereas you seem to operate on the 2.4 library.
A partially initialized module object is left behind in sys.modules and seen
by further import attempts.
$ cat arbitrary.py
import not_there
def f():
print "you ain't gonna see that"
$ python
Python 2.3.3 (#1, Apr 6 2004, 01:47:39)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import arbitrary
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "arbitrary.py", line 2, in ?
import not_there
ImportError: No module named not_there
>>> import arbitrary
>>> arbitrary.f()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'f'
>>>
I have no experience with import hooks, but for normal imports that has been
fixed in Python 2.4:
$ py24
Python 2.4 (#5, Jan 4 2005, 10:14:01)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import arbitrary
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "arbitrary.py", line 2, in ?
import not_there
ImportError: No module named not_there
>>> import arbitrary
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "arbitrary.py", line 2, in ?
import not_there
ImportError: No module named not_there
>>>
Peter
More information about the Python-list
mailing list