classification
Title: csv.writer
Type: behavior Stage:
Components: Versions: Python 2.6
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: skip.montanaro, zacktu (2)
Priority: Keywords

Created on 2009-10-24 22:07 by zacktu, last changed 2009-10-24 23:11 by zacktu.

Messages (3)
msg94437 - (view) Author: Bob Cannon (zacktu) Date: 2009-10-24 22:08
I used csv.writer to open a file for writing with comma as separator and
dialect='excel'.  I used writerow to write each row into the file.  When
I execute under linux, each line is terminated by '\r\n'.  When I
execute under windows, each line is terminated by '\r\r\n'.  Thus, under
MS Windows, when I read the csv file, there is a blank line between each
significant line.  I have dropped cvs.writer and now build each line
manually and terminate it with '\n'.  When the line is written in
windows, it is terminated by '\r\n'.  That's what should happen.  

As I see it, writerow with dialect='excel' should only terminate a line
with '\n'.  Windows will automatically place a '\r' in front of the '\n'.
msg94438 - (view) Author: Skip Montanaro (skip.montanaro) Date: 2009-10-24 22:52
Your output file should be opened in binary mode.  Sounds like you
opened it in text mode.
msg94441 - (view) Author: Bob Cannon (zacktu) Date: 2009-10-24 23:10
Probably so.  I'm sorry to report this as a bug if it's not.  I asked
abut this on a Python group on IRC and got no suggestions.  Thanks for
taking a look.
History
Date User Action Args
2009-10-24 23:11:18zacktusetstatus: open -> closed
2009-10-24 23:10:41zacktusetmessages: + msg94441
2009-10-24 22:52:30skip.montanarosetnosy: + skip.montanaro
messages: + msg94438
2009-10-24 22:08:39zacktusetmessages: + msg94437
2009-10-24 22:07:03zacktucreate