Blank rows resulting from simple csv script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Drew

    #1

    Blank rows resulting from simple csv script

    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

  • Michael Bentley

    #2
    Re: Blank rows resulting from simple csv script


    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.

    Comment

    Working...