<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 11, 2013 at 1:26 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve+comp.lang.python@pearwood.info" target="_blank">steve+comp.lang.python@pearwood.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">inshu chauhan wrote:<br>
<br>
> In the programme below I am trying to read two csv format files and<br>
> process them and write a new file with some of theirs data.<br>
><br>
> import csv<br>
> f1_reader = csv.reader(open(r"Z:\Weka<br>
> work\Feature_Vectors_Fullset_00.arff"))<br>
> f2_reader = csv.reader(open(r"Z:\Weka<br>
> work\Feature_Vectors_Fullset_00_noxy+class.arff"))<br>
> nf = open(r"Z:\Weka work\classified_image00_withoutxy.arff", "w")<br>
><br>
> while True:<br>
> l1 = f1_reader.next()<br>
> while len(l1) != 12:<br>
> l1 = f1_reader.next()<br>
> l2 = f2_reader.next()<br>
> while len(l2) != 11:<br>
> l2 = f2_reader.next()<br>
><br>
> ix = l1[0].strip()<br>
> iy = l1[1].strip()<br>
> classification = l2[8].strip()<br>
><br>
> print >> nf, ix, iy, classification<br>
><br>
> nf.close()<br>
><br>
> This programme is giving me this error now :<br>
><br>
> Traceback (most recent call last):<br>
> File "Z:\Weka work\final_image_classificationwithoutxy.py", line 16, in<br>
> <module><br>
> l2 = f2_reader.next()<br>
> StopIteration<br>
><br>
><br>
> what could be a possible reason to StopIteration ???<br>
<br>
</div></div>next() raises StopIteration when there is nothing else to return.<br>
<br>
<br>
py> it = iter([1, 2, 3])<br>
py> it.next()<br>
1<br>
py> it.next()<br>
2<br>
py> it.next()<br>
3<br>
py> it.next()<br>
<div class="im">Traceback (most recent call last):<br>
</div> File "<stdin>", line 1, in <module><br>
StopIteration<br>
<br>
<br>
You have reached the end of the file and there is nothing else for the CSV<br>
reader to return, so it raises StopIteration.<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br><br></div><div>But why does it has nothing to return so early before traversing the whole file ? Is there any way it can be corrected ? And also the programme isn't writing anything to the file ? <br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888">
<br>
<br>
</font></span></blockquote></div><br></div></div>