Puzzling difference between module and package.module
Huaiyu Zhu
huaiyu at gauss.almadan.ibm.com
Fri Mar 22 15:12:23 EST 2002
A mystery for everyone's curiosity! (It might even be a Python bug.)
I hope someone can recognize what would cause
import dir2.file1 # in dir1
import file1 # in dir1/dir2
to behave quite differently in the following directory structure:
dir1
dir2
__init__.py (empty file)
file1.py
Here's a test program that uses the Gnuplot package:
------------------- test_plot.py ------------
x = [range(5), range(1,6)]
from Gnuplot import Gnuplot
g = Gnuplot()
g.plot(x)
from time import sleep
sleep(.1)
print 'after sleep'
---------------------------------------------
It is OK to run 'import test_plot' in dir2. But running 'import
dir2.test_plot' in dir1 generates an error:
after sleep
tmpfile /tmp/@2065.0 None <Gnuplot.PlotItems.TempFile instance at 0x81bf78c>
Exception exceptions.AttributeError: "'NoneType' object has no attribute
'system'" in <bound method TempFile.__del__ of <Gnuplot.PlotItems.TempFile
instance at 0x81bf78c>> ignored
When trying in an interpreter, the error comes up while exiting the interpreter.
The relevant sections are (I've added some diagnostic statements)
-------------------- Gnuplot/PlotItems.py --------------------
import os, string, tempfile
class TempFile(AnyFile):
def __del__(self):
try:
os.unlink(self.filename)
except:
print 'tmpfile', self.filename, `os`, self
os.system('ls -l %s' % self.filename)
raise SystemExit
---------------------------------------------------------------
So it appears that Gnuplot.PlotItems.os somehow becomes None. How does that
happen? I can understand that if the module attribute simply dissappears,
that would be caused by a mismatched order of clean up. But how is it
changed to None?
It appears that this bug first appeared in Python 2.2:
$ echo import testdir.test_plot | python2.0
after sleep
$ echo import testdir.test_plot | python2.1
after sleep
$ echo import testdir.test_plot | python2.2
after sleep
Exception exceptions.AttributeError: "'NoneType' object has no attribute
'unlink'" in <bound method TempFile.__del__ of <Gnuplot.PlotItems.TempFile
instance at 0x81bd034>> ignored
$ echo import testdir.test_plot | python2.3
after sleep
tmpfile /tmp/@2252.0 None <Gnuplot.PlotItems.TempFile instance at 0x81bf8cc>
Exception exceptions.AttributeError: "'NoneType' object has no attribute
'system'" in <bound method TempFile.__del__ of <Gnuplot.PlotItems.TempFile
instance at 0x81bf8cc>> ignored
The versions used are:
Python 2.0 (#1, Mar 1 2001, 02:42:21) [GCC 2.95.2 19991024 (release)] on linux2
Python 2.1 (#1, Oct 2 2001, 15:35:43) [GCC 2.95.2 19991024 (release)] on linux2
Python 2.2 (#4, Mar 6 2002, 14:33:41) [GCC 2.95.2 19991024 (release)] on linux2
Python 2.3a0 (#5, Mar 20 2002, 12:38:28) [GCC 2.95.3 20010315 (SuSE)] on linux2
Should I file a bug report?
Huaiyu
More information about the Python-list
mailing list