Puzzling difference between module and package.module 
Author Message
 Puzzling difference between module and package.module

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

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

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



Wed, 08 Sep 2004 04:12:23 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. package.module != module

2. Module Packages - package-search-strategy controversy

3. scoping/module life puzzle

4. about differences of exec and async_exec in postgres module

5. Difference between MOD_PYTHON and the CGI module

6. Treatment of modules by Fortran 90 compilers - differences ?

7. differences between module and common block

8. module name differences depending on how generated

9. modules what modules

10. Module information in load-module

11. including modules => installing modules

12. Module for showRE and other modules, generally?

 

 
Powered by phpBB® Forum Software