Simple csv read/write

Discussion in 'Python' started by Drew, Apr 24, 2007.

  1. Drew

    Drew Guest

    Ok, I'm trying to do the simplest read/write from one csv file to
    another. For some reason, every other row on the output file is a
    blank row. What am I doing wrong?

    import csv

    reader = csv.reader(open('current.csv'))
    writer = csv.writer(open('new.csv','w'))

    for line in reader:
    writer.writerow(line)
     
    Drew, Apr 24, 2007
    #1
    1. Advertising

  2. Drew

    John Machin Guest

    On 25/04/2007 8:27 AM, Drew wrote:
    > Ok, I'm trying to do the simplest read/write from one csv file to
    > another. For some reason, every other row on the output file is a
    > blank row. What am I doing wrong?
    >
    > import csv
    >
    > reader = csv.reader(open('current.csv'))
    > writer = csv.writer(open('new.csv','w'))
    >
    > for line in reader:
    > writer.writerow(line)
    >


    1. Try reading the responses already posted to your previous questions.

    2. Try reading the documentation; for each of csv.reader and csv.writer,
    it says "If csvfile is a file object, it must be opened with the 'b'
    flag on platforms where that makes a difference."
     
    John Machin, Apr 25, 2007
    #2
    1. Advertising

  3. Drew

    Drew Guest

    On Apr 24, 8:35 pm, John Machin <> wrote:
    > On 25/04/2007 8:27 AM, Drew wrote:
    >
    > > Ok, I'm trying to do the simplest read/write from one csv file to
    > > another. For some reason, every other row on the output file is a
    > > blank row. What am I doing wrong?

    >
    > > import csv

    >
    > > reader = csv.reader(open('current.csv'))
    > > writer = csv.writer(open('new.csv','w'))

    >
    > > for line in reader:
    > > writer.writerow(line)

    >
    > 1. Try reading the responses already posted to your previous questions.
    >
    > 2. Try reading the documentation; for each of csv.reader and csv.writer,
    > it says "If csvfile is a file object, it must be opened with the 'b'
    > flag on platforms where that makes a difference."


    My apologies to the rest of the list, issues with groups.google.com
    cause the multiple posts.
     
    Drew, Apr 26, 2007
    #3
    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. Chris
    Replies:
    3
    Views:
    250
    Steven D'Aprano
    Sep 11, 2007
  2. jliu66
    Replies:
    0
    Views:
    517
    jliu66
    Oct 19, 2007
  3. Li Chen
    Replies:
    18
    Views:
    669
    Azmi Farih
    Mar 23, 2010
  4. sahm
    Replies:
    4
    Views:
    689
  5. Sacha Rook

    csv read clean up and write out to csv

    Sacha Rook, Nov 2, 2012, in forum: Python
    Replies:
    2
    Views:
    223
    Hans Mulder
    Nov 2, 2012
Loading...

Share This Page