Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38688 > unrolled thread
| Started by | inshu chauhan <insideshoes@gmail.com> |
|---|---|
| First post | 2013-02-11 15:42 +0100 |
| Last post | 2013-02-11 15:42 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Error in reading and writing CSV format file in python inshu chauhan <insideshoes@gmail.com> - 2013-02-11 15:42 +0100
| From | inshu chauhan <insideshoes@gmail.com> |
|---|---|
| Date | 2013-02-11 15:42 +0100 |
| Subject | Re: Error in reading and writing CSV format file in python |
| Message-ID | <mailman.1654.1360593748.2939.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
On Mon, Feb 11, 2013 at 3:22 PM, Dave Angel <davea@davea.name> wrote: > On 02/11/2013 06:00 AM, inshu chauhan wrote: > >> In the programme below I am trying to read two csv format files and >> process >> them and write a new file with some of theirs data. >> >> import csv >> f1_reader = csv.reader(open(r"Z:\Weka >> work\Feature_Vectors_Fullset_**00.arff")) >> f2_reader = csv.reader(open(r"Z:\Weka >> work\Feature_Vectors_Fullset_**00_noxy+class.arff")) >> nf = open(r"Z:\Weka work\classified_image00_**withoutxy.arff", "w") >> >> while True: >> l1 = f1_reader.next() >> while len(l1) != 12: >> l1 = f1_reader.next() >> l2 = f2_reader.next() >> while len(l2) != 11: >> l2 = f2_reader.next() >> >> ix = l1[0].strip() >> iy = l1[1].strip() >> classification = l2[8].strip() >> >> print >> nf, ix, iy, classification >> >> nf.close() >> >> This programme is giving me this error now : >> >> Traceback (most recent call last): >> File "Z:\Weka work\final_image_**classificationwithoutxy.py", line >> 16, in >> <module> >> l2 = f2_reader.next() >> StopIteration >> >> >> what could be a possible reason to StopIteration ??? >> >> >> I checked the syntax and usage of this module looks alright to me , but >> then why this error ? >> >> >> > That's not an error, it's just a normal way to end a for-loop. If you > were using a syntax like: > for item in f2_reader: > > the StopIteration would simply end the loop. Since you're doing it > manually, you have to handle the exception yourself. > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > Yes , therefore I used try and except.
Back to top | Article view | comp.lang.python
csiph-web