Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Csv blank rows problem with Excel

Tags:

python

csv

excel

I have a csv file which contains rows from a sqlite3 database. I wrote the rows to the csv file using python.

When I open the csv file with Ms Excel, a blank row appears below every row, but the file on notepad is fine(without any blanks).

Does anyone know why this is happenning and how I can fix it?

Edit: I used the strip() function for all the attributes before writing a row.

Thanks.

like image 725
optimus Avatar asked Nov 08 '10 10:11

optimus


1 Answers

You're using open('file.csv', 'w')--try open('file.csv', 'wb').

The Python csv module requires output files be opened in binary mode.

like image 173
robert Avatar answered Oct 11 '22 18:10

robert