Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38672

Re: Error in reading and writing CSV format file in python

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 <insideshoes@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'raises': 0.07; 'subject:Error': 0.07; 'subject:file': 0.07; '"w")': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; '&gt;&gt;': 0.16; 'csv': 0.16; 'return,': 0.16; 'subject:CSV': 0.16; 'subject:writing': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'true:': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'feb': 0.19; 'trying': 0.21; 'import': 0.21; '"",': 0.22; 'cc:2**0': 0.23; '&gt;': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(most': 0.27; '???': 0.27; 'message-id:@mail.gmail.com': 0.27; "d'aprano": 0.29; 'steven': 0.29; 'skip:& 10': 0.29; 'error': 0.30; 'file': 0.32; 'could': 0.32; 'print': 0.32; '11,': 0.33; 'traceback': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'there': 0.35; 'but': 0.36; 'data.': 0.36; 'anything': 0.36; 'possible': 0.37; 'does': 0.37; 'two': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'nothing': 0.38; 'end': 0.40; 'skip:w 30': 0.61; 'reached': 0.65; 'programme': 0.69; '11:': 0.84; '12:': 0.84; '2013': 0.84; 'theirs': 0.84
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=BmXqhkCjaiIeqaVOVtWMA5IS7mIWsWEmxCi5xshb/R4=; b=ChqyXuBAzUtjGKaULThLdtG5hKqwZiJxb2USQ5GA/NiDYO230MMST1NwfHhiH/D3UP S7fiYEp05JucTBSgJMl9qVerJaNtqs5blVXdnBnTJp2+CzK9RC/TQPUduHT8SS9SVw9f gsNR5wvhppETTV4AEg9X9zMC4bKePtXdRSv9BWyxpa+JEiwp686YBQtaTQn0ZOJXbUM9 i6Cex7H1VzKRJ5MQZ5fpa/sTskrGbS7yQVUALYb41Y1wqyYuygOo3AeITfZG+NIZbnOg pNkIAu1knT2cDMFWvo1J/NAFRfeCwnqfz5s9pbEajtLc8NT+4yhMSN/zIQRD4S01OtpS GgmA==
MIME-Version 1.0
X-Received by 10.50.196.227 with SMTP id ip3mr11410320igc.97.1360586640362; Mon, 11 Feb 2013 04:44:00 -0800 (PST)
In-Reply-To <5118e383$0$29985$c3e8da3$5496439d@news.astraweb.com>
References <mailman.1634.1360580421.2939.python-list@python.org> <5118e383$0$29985$c3e8da3$5496439d@news.astraweb.com>
Date Mon, 11 Feb 2013 13:44:00 +0100
Subject Re: Error in reading and writing CSV format file in python
From inshu chauhan <insideshoes@gmail.com>
To "Steven D'Aprano" <steve+comp.lang.python@pearwood.info>
Content-Type multipart/alternative; boundary=14dae934117b628eca04d572432a
Cc "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1642.1360586648.2939.python-list@python.org> (permalink)
Lines 158
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360586648 news.xs4all.nl 6876 [2001:888:2000:d::a6]:42156
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38672

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Mon, Feb 11, 2013 at 1:26 PM, Steven D'Aprano <
steve+comp.lang.python@pearwood.info> wrote:

> 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 ???
>
> next() raises StopIteration when there is nothing else to return.
>
>
> py> it = iter([1, 2, 3])
> py> it.next()
> 1
> py> it.next()
> 2
> py> it.next()
> 3
> py> it.next()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> StopIteration
>
>
> You have reached the end of the file and there is nothing else for the CSV
> reader to return, so it raises StopIteration.
>


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 ?

>
>
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Error in reading and writing CSV format file in python inshu chauhan <insideshoes@gmail.com> - 2013-02-11 12:00 +0100
  Re: Error in reading and writing CSV format file in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-11 23:26 +1100
    Re: Error in reading and writing CSV format file in python inshu chauhan <insideshoes@gmail.com> - 2013-02-11 13:44 +0100
    Re: Error in reading and writing CSV format file in python MRAB <python@mrabarnett.plus.com> - 2013-02-11 13:02 +0000
    Re: Error in reading and writing CSV format file in python inshu chauhan <insideshoes@gmail.com> - 2013-02-11 14:09 +0100

csiph-web