473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

Apr 24 '07 #1
2 7328
Drew schrieb:
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?
The modes aren't compatible - either use rb, wb or r,w

Diez
Apr 24 '07 #2
On 25/04/2007 6:17 AM, Diez B. Roggisch wrote:
Drew schrieb:
>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?

The modes aren't compatible - either use rb, wb or r,w
Bzzzzt! *ALWAYS* use binary mode for both reading and writing.
Apr 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: dan glenn | last post by:
Hi. I'm finding that if I have text entered into a <textarea ...> </textarea> in a form, and that text has leading blank lines (with no spaces or anything else), that when I retrieve the entered...
1
by: Peter Kleiner | last post by:
Greetings all, I have a database with two tables: docs and edocs. For each record in docs there can be zero to unlimited records in edocs. Both tables have an integer primary key named index. ...
9
by: Kay | last post by:
Hi all, Could you tell me the best way to add a blank item(as first item) in a data binded combo box? Because I think I didn't do it right and it generate an error if the second item(after the...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
2
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so...
7
by: Janis | last post by:
I try to understand what could be the source of a problem with displaying and hiding rows of tables using display:block/none. I've read selfhtml but could not find any hint about that. Any...
0
by: yongsheng | last post by:
Hi, i've searched through the discussions but haven't got a clue to solve my problem. Im new to VBA, maybe its a simple task but any help is welcomed. The Problem: Every month, I need to sort...
1
by: Drew | last post by:
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 =...
2
by: DavidPr | last post by:
I'm creating (trying to create) a picture gallery for my website. The script is not working. I've been working on it now for about 80 hours with no success. My php skills aren't very good. This...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.