slight csv misbehavior under Windows

Skip Montanaro skip at pobox.com
Mon Aug 18 17:24:10 CEST 2003


    Thomas> produces lines ending 0d0d0a, and when you load this into Excel
    Thomas> 97 the data appears double-spaced.

    Thomas> Opening the file with 'wb' solves the problem, but it would be
    Thomas> lovely were this either fixed or documented; it's rather
    Thomas> unintuitive that a file opened with 'wb' still ends lines with
    Thomas> 0d0a.

It is documented.  You have to open CSV files in binary mode.  In the csv
module docs it states the following for both the reader and writer factory
functions:

    If csvfile is a file object, it must be opened with the 'b' flag on
    platforms where that makes a difference.

It makes a difference on Windows, so you need to use 'b'.  

Skip





More information about the Python-list mailing list