Blank rows resulting from simple csv script

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

  1. Drew

    Drew Guest

    Hi all -

    I've written a simple script to read a .csv file and then write out
    rows to a new file only if the value in the 4th column is a 0. Here's
    the code:

    import csv

    reader = csv.reader(open('table_export.csv','rb'))

    writer = csv.writer(open('new_jazz.csv','w'))

    for row in reader:
    if row[3] == '0':
    writer.writerow(row)

    This is writing out the correct rows, however it is writing a blank
    row between each of the rows written out. Any ideas?

    Thanks,
    Drew
    Drew, Apr 24, 2007
    #1
    1. Advertising

  2. On Apr 24, 2007, at 3:35 PM, Drew wrote:

    > Hi all -
    >
    > I've written a simple script to read a .csv file and then write out
    > rows to a new file only if the value in the 4th column is a 0. Here's
    > the code:
    >
    > import csv
    >
    > reader = csv.reader(open('table_export.csv','rb'))
    >
    > writer = csv.writer(open('new_jazz.csv','w'))
    >
    > for row in reader:
    > if row[3] == '0':
    > writer.writerow(row)
    >
    > This is writing out the correct rows, however it is writing a blank
    > row between each of the rows written out. Any ideas?


    Write in binary mode.
    Michael Bentley, Apr 24, 2007
    #2
    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. Bjorn Jensen
    Replies:
    2
    Views:
    815
    Bjorn Jensen
    Mar 22, 2005
  2. James Wallace
    Replies:
    0
    Views:
    1,039
    James Wallace
    Oct 17, 2003
  3. Subba Rao via DotNetMonster.com

    script for moving rows up and down and traverse thru rows of HTML table

    Subba Rao via DotNetMonster.com, Mar 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    8,199
    Subba Rao via DotNetMonster.com
    Mar 19, 2005
  4. =?Utf-8?B?Um9iIE5lbGRlcg==?=

    OutputStream.Write with PDF resulting in blank page in IE

    =?Utf-8?B?Um9iIE5lbGRlcg==?=, Jun 29, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    5,599
  5. Drew
    Replies:
    2
    Views:
    315
    John Machin
    Apr 25, 2007
Loading...

Share This Page