<div class="gmail_quote">On Fri, Feb 3, 2012 at 10:46 AM, Simeon Tesfaye <span dir="ltr">&lt;<a href="mailto:Simeon.Tesfaye@eaudeparis.fr">Simeon.Tesfaye@eaudeparis.fr</a>&gt;</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>&quot;shapefile=shapefile.Reader(&quot;file.shp&quot;)<br>shps=shapefile.shapes()<br>shprec = shapefile.records()<br>&quot;</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>&quot;Traceback (most recent call last):<br>  File &quot;&lt;pyshell#9&gt;&quot;, line 1, in &lt;module&gt;<br>    troncop=troncon.shapes()<br>  File &quot;C:\Python25\Lib\shapefile.py&quot;, line 310, in shapes<br>
    while shp.tell() &lt; self.shpLength:<br>  File &quot;C:\Python25\Lib\shapefile.py&quot;, line 222, in __shape<br>    print(f.read(8))<br>  File &quot;C:\Python25\lib\struct.py&quot;, line 87, in unpack<br>    return o.unpack(s)<br>
error: unpack requires a string argument of length 8&quot;</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 &quot;unpack&quot; it in PYTHON.</div>
<div> </div>
<div>I&#39;ve tried putting an &quot;IF&quot; 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&#39;ve also tried skipping the &quot;unpack&quot; part altogther, not with much success.</div>
<div> </div>
<div>I&#39;m really not too familiar with Python, si if anyone could help me out with this, I&#39;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>