os.path.exists() strangeness with pytest.py (Re: swig expert)

Bernhard Reiter bernhard at intevation.de
Sat Oct 14 23:15:41 CEST 2006


On Friday 06 October 2006 18:06, Didrik Pinte wrote:
> [2] The second problem is really strange :
>
> When calling the original libraries/pyshapelib/pytest.py, everything
> works fine BUT if you do the following, you get an error :
>
> Original code :
> --------------------------------------------------------------------
> make_shapefile("testfile")
> read_shapefile("testfile")
> --------------------------------------------------------------------
>
> Modified code causing the bug :
> --------------------------------------------------------------------
> make_shapefile("testfile")
> import os
> os.path.exists("testfile.shp")
> read_shapefile("testfile")
> --------------------------------------------------------------------
> Output :
>
> ([10.0, 10.0, 0.0, 0.0], [20.0, 20.0, 0.0, 0.0])
> [[(10.0, 10.0), (10.0, 20.0), (20.0, 20.0), (10.0, 10.0)]]
> ([0.0, 0.0, 0.0, 0.0], [40.0, 40.0, 0.0, 0.0])
> [[(0.0, 0.0), (0.0, 40.0), (40.0, 40.0), (40.0, 0.0), (0.0, 0.0)],
> [(10.0, 10.0), (20.0, 10.0), (20.0, 20.0), (10.0, 20.0), (10.0, 10.0)]]
> Traceback (most recent call last):
>   File "pytest.py", line 88, in ?
>     os.path.exists("testfile.shp")
>   File "/usr/lib/python2.4/posixpath.py", line 171, in exists
>     st = os.stat(path)
> TypeError: shapefile already closed
>
> It is like if the handle was closed but still kept some kind of
> reference on the previously opened shapefile.

This is strange. 
There should not be a connection between os.path.exists() 
and the other code. One thing that could cause this would be
earlier memory corruption. I wonder if there is a way to automatically
check for problems like this in Python modules.

Bernhard

-- 
Managing Director - Owner, www.intevation.net       (Free Software Company)
Germany Coordinator, fsfeurope.org       (Non-Profit Org for Free Software)
www.kolab-konsortium.com   (Email/Groupware Solution, Professional Service)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20061014/b1e703fc/attachment.bin


More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)