[Python-Dev] CSV, bytes and encodings
solipsis at pitrou.net
Wed Apr 1 12:53:19 CEST 2009
<skip <at> pobox.com> writes:
> Antoine> The documentation is, IMO, wrong even in 2.x. Just yesterday I
> Antoine> had to open a CSV file in 'rU' mode because it had Windows line
> Antoine> endings and I'm under Linux....
> See above. You almost certainly didn't have fields containing CRLF pairs or
> didn't care that while reading the file your data values were silently
Perhaps. But without using 'rU' the file couldn't be read at all.
(I'm not sure it was Windows line endings by the way; perhaps Macintosh ones;
anyway, it didn't work using 'rb')
I have to add that if individual fields really can contain newlines, then the
CSV module ought to be smarter when /saving/ those fields. I've inadvertently
tried to produce a CSV file with such fields and it ended up wrong when opened
as a spreadsheet (text after the newlines was ignored in Gnumeric and in
OpenOffice, while Excel displayed a spurious additional row containing only the
text after the newline).
More information about the Python-Dev