开发者

Csv blank rows problem with Excel

I hav开发者_运维技巧e 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.


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

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


the first that comes into my mind (just an idea) is that you might have used "\r\n" as row delimiter (which is shown as one linebrak in notepad) but excel expects to get only "\n" or only "\r" and so it interprets this as two line-breaks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜