<div class="gmail_quote">On Fri, Feb 3, 2012 at 10:46 AM, Simeon Tesfaye <span dir="ltr"><<a href="mailto:Simeon.Tesfaye@eaudeparis.fr">Simeon.Tesfaye@eaudeparis.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="MARGIN:4px 4px 1px;FONT:10pt Tahoma">
<div>Hello everyone,</div>
<div> </div>
<div>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.</div>
<div>So, I open up my shapefile (data is polylines, meaning, not points or polygons)</div>
<div>"shapefile=shapefile.Reader("file.shp")<br>shps=shapefile.shapes()<br>shprec = shapefile.records()<br>"</div>
<div>Then I carry out some edits, and I save my file.</div>
<div>When I want to open it again, within the same script, in order to access some of the data I just modified, I get this message :</div>
<div> </div>
<div>"Traceback (most recent call last):<br> File "<pyshell#9>", line 1, in <module><br> troncop=troncon.shapes()<br> File "C:\Python25\Lib\shapefile.py", line 310, in shapes<br>
while shp.tell() < self.shpLength:<br> File "C:\Python25\Lib\shapefile.py", line 222, in __shape<br> print(f.read(8))<br> File "C:\Python25\lib\struct.py", line 87, in unpack<br> return o.unpack(s)<br>
error: unpack requires a string argument of length 8"</div>
<div> </div>
<div> </div>
<div>I reckon this part tries to import header information for shape data, which would be stored in C (?), and fails to "unpack" it in PYTHON.</div>
<div> </div>
<div>I've tried putting an "IF" to check whether f.read(8) was actually a string (type) and of length equal to 8. I still get the same error message.</div>
<div>I've also tried skipping the "unpack" part altogther, not with much success.</div>
<div> </div>
<div>I'm really not too familiar with Python, si if anyone could help me out with this, I'd be really grateful.</div>
<div> </div>
<div>Thanks in advance,</div>
<div> </div>
<div>S.T.<br></div></div>
<br>_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br>All that this error means is that you have an array longer than the number of values that you are assigning to it.<div>I.E:</div><div>array = [1, 2, 3]</div><div>a, b = array</div><div>This causes an error since there are too many values in the array. To fix this, just change the second line to:</div>
<div>a, b = array[:2]</div><div>in my example.<br clear="all"><div><br></div>-- <br>My Blog - Defenestration Coding<div><br></div><div><a href="http://defenestrationcoding.wordpress.com/" target="_blank">http://defenestrationcoding.wordpress.com/</a></div>
<br>
</div>