Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'exception': 0.03; 'syntax': 0.03; 'subject:Error': 0.07; 'subject:file': 0.07; '"w")': 0.09; 'loop.': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; '>>': 0.16; 'csv': 0.16; 'subject:CSV': 0.16; 'subject:writing': 0.16; 'true:': 0.16; '\xa0print': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'feb': 0.19; 'module': 0.19; 'trying': 0.21; 'import': 0.21; '\xa0if': 0.22; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'looks': 0.26; '(most': 0.27; 'am,': 0.27; '???': 0.27; 'message-id:@mail.gmail.com': 0.27; 'url:mailman': 0.29; 'skip:& 10': 0.29; 'error': 0.30; 'checked': 0.30; 'url:python': 0.32; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'url:listinfo': 0.32; '11,': 0.33; 'like:': 0.33; 'traceback': 0.33; 'handle': 0.33; 'received:google.com': 0.34; 'doing': 0.35; 'pm,': 0.35; 'but': 0.36; 'url:org': 0.36; 'data.': 0.36; 'possible': 0.37; 'two': 0.37; 'why': 0.37; 'item': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'end': 0.40; 'url:mail': 0.40; 'therefore': 0.65; 'programme': 0.69; '11:': 0.84; '12:': 0.84; '2013': 0.84; 'theirs': 0.84; 'angel': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=7IOsbeeABDM+BafLe5BvBjIQTFlZDblVyb+rupphbZ0=; b=TR0M7ES289iTptq7wuU6IOhvi0NtcnE2ccUVjR2My7Km8PwgD2kejfJdreNuEfa8vB izgKYf4+nFe0YrRMbYhB4tsWMqZYynhx0hP1znzGd8r6yyoZSqJpI88Xg121fEf7pQCJ VO5H+WfiyRZkCQ9/wL6hh3+mGOB+IYoqecP3pfmX1ZeqysGlSRdaekla3ccipqPjr23d Tie1AGN3dqw5e2pScJ4eCeWS6RKAWeItm/qiJFHitCjYYtm7+fBIDZxU4bvNzbzRr75J v6Mw24QqC+o3vUWNV5Zy6ixSiZtz7eN5weiu5U6/1Bz11NXK9+ObGAYJksaZiW28G2q1 lSuw== MIME-Version: 1.0 X-Received: by 10.50.46.132 with SMTP id v4mr11716077igm.72.1360593738911; Mon, 11 Feb 2013 06:42:18 -0800 (PST) In-Reply-To: <5118FE9B.4090303@davea.name> References: <5118FE9B.4090303@davea.name> Date: Mon, 11 Feb 2013 15:42:18 +0100 Subject: Re: Error in reading and writing CSV format file in python From: inshu chauhan To: Dave Angel Content-Type: multipart/alternative; boundary=14dae93410797dd15004d573eaff Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 146 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360593748 news.xs4all.nl 6939 [2001:888:2000:d::a6]:52437 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38688 --14dae93410797dd15004d573eaff Content-Type: text/plain; charset=ISO-8859-1 On Mon, Feb 11, 2013 at 3:22 PM, Dave Angel 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 >> >> 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 > Yes , therefore I used try and except. --14dae93410797dd15004d573eaff Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Mon, Feb 11, 2013 at 3:22 PM, Dave Angel <<= a href=3D"mailto:davea@davea.name" target=3D"_blank">davea@davea.name&g= t; wrote:
On 0= 2/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 =3D csv.reader(open(r"Z:\Weka
work\Feature_Vectors_Fullset_00.arff"))
f2_reader =3D csv.reader(open(r"Z:\Weka
work\Feature_Vectors_Fullset_00_noxy+class.arff"))
nf =3D open(r"Z:\Weka work\classified_image00_withoutxy.arff&qu= ot;, "w")

while True:
=A0 =A0 =A0l1 =3D f1_reader.next()
=A0 =A0 =A0while len(l1) !=3D 12:
=A0 =A0 =A0 =A0 =A0l1 =3D f1_reader.next()
=A0 =A0 =A0l2 =3D f2_reader.next()
=A0 =A0 =A0while len(l2) !=3D 11:
=A0 =A0 =A0 =A0 =A0l2 =3D f2_reader.next()

=A0 =A0 =A0ix =3D l1[0].strip()
=A0 =A0 =A0iy =3D l1[1].strip()
=A0 =A0 =A0classification =3D l2[8].strip()

=A0 =A0 =A0print >> nf, ix, iy, classification

nf.close()

This programme is giving me this error now :

Traceback (most recent call last):
=A0 =A0File "Z:\Weka work\final_image_classificationwithoutxy.p= y", line 16, in
<module>
=A0 =A0 =A0l2 =3D 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. =A0I= f you were using a syntax like:
=A0 for item in f2_reader:

the StopIteration would simply end the loop. =A0Since you're doing it m= anually, you have to handle the exception yourself.<= font color=3D"#888888">


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list

Yes ,= therefore I used try and except.
--14dae93410797dd15004d573eaff--