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

Discussion in 'Python' started by MRAB, Feb 11, 2013.

  1. MRAB

    MRAB Guest

    On 2013-02-11 11:00, 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 ?
    >

    It has reached the end of the file, there's no next line.
     
    MRAB, Feb 11, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    480
    Thomas Ganss
    Jan 15, 2006
  2. Tintin92
    Replies:
    1
    Views:
    1,806
    Andrew Thompson
    Feb 14, 2007
  3. Steven D'Aprano
    Replies:
    1
    Views:
    153
  4. Dave Angel
    Replies:
    0
    Views:
    159
    Dave Angel
    Feb 11, 2013
  5. Replies:
    3
    Views:
    91
    Jason Friedman
    Apr 2, 2014
Loading...

Share This Page