473,506 Members | 17,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7335
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
3260
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
3097
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
4437
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
3984
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
3100
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
3049
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
1289
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
313
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
2042
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
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.