I just realized my first email was not very self explanatory, so let me start over. My system is Windows XP Professional, with Python 2.5, and the library I'm experiencing trouble with is pyshp, available (single version for all systems) here : http://code.google.com/p/pyshp/ Here is the correct error message I get (I removed my failed attempt at correcting the library, thanks for pointing that out Dave) : Traceback (most recent call last):
"File "<pyshell#3>", line 1, in <module> rsh=shreader.shapes() File "C:\Python25\shapefile.py", line 310, in shapes shapes.append(self.__shape()) File "C:\Python25\shapefile.py", line 222, in __shape (recNum, recLength) = unpack(">2i", f.read(8)) File "C:\Python25\lib\struct.py", line 87, in unpack return o.unpack(s) error: unpack requires a string argument of length 8" My code can be summarized as that "f=shapefile.Editor(shapefile="C:\Sampler\Shpfiles\ROUTE.shp") f.line(parts=[[coord[0],[0,0],[10,10]]]) f.record("i put my attributes here") f.save('ROUTE')" The error happens when I do "shreader=shapefile.Reader("ROUTE.shp") rsh=shreader.shapes()" afterwards. @ Alex : I didn't read instead of editing, it was a typo in my initial message, sorry but thanks anyway @ Dave : There is no binary data in my file that I'm aware of, if you mean in the shapefile, I reckon the library takes care of it, otherwise it would'nt work at all ? @ Nate : OK, but I do not understand where to put your correction ? f.read(8) seems to be required to have a length of 8, due to the format of the unpack ("<2i"), but even though I tried to replace it with f.read(8)[:8], it does not work. Sorry again if I seem kinda slow, I'm really a beginner in python coding. ST >>> Савицкий Александр<alexx...@gmail.com> 06/02/2012 07:14 >>> I am having a bit of trouble here with my code, which uses a shapefile library, named pyshp, to import, edit, and save GIS files within Python. So, I open up my shapefile (data is polylines, meaning, not points or polygons) "shapefile=shapefile.Reader("file.shp") shps=shapefile.shapes() shprec = shapefile.records() " Then I carry out some edits, and I save my file. If you wish to edit your shapefiles, you need to create object: shapefile.Editor() or shapefile.Write() - if you want create new file. and then save your edits... shapefile.Reader object/class for READING shapefile, not for edit/update
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor