[Python-Dev] CSV, bytes and encodings

R. David Murray rdmurray at bitdance.com
Thu Apr 2 07:27:05 CEST 2009


On Thu, 2 Apr 2009 at 07:23, Antoine Pitrou wrote:
> Le mercredi 01 avril 2009 à 18:22 -0400, R. David Murray a écrit :
>> I just added some tests to trunk that seem to indicate this case is
>> handled correctly in terms of preserving the data.  Maybe you didn't
>> write the file such that the fields with the newlines were quoted?
>
> I used the default csv.writer into a StringIO, and the whole was then
> returned as the response of an HTTP request (with the proper
> Content-Type and Content-Disposition headers). I assume quoting is
> enabled by default?

Yes, it is.  The files I've encountered that had embedded newlines I
never tried to open in Excel or any other spreadsheet, so all _I'm_
sure of is that Excel produces them.

>> And of course how non-Excel applications handle that data on import
>> can be different from how Excel handles it.
>
> Of course, but when three major spreadsheet software (including Excel
> itself) choke on the embedded newline, there might be a problem (or
> not :)).
> (please note that as for Excel I couldn't test myself, a client of mine
> did)

I've made a note to test this, out of curiosity, when I get home.

--David


More information about the Python-Dev mailing list