slight csv misbehavior under Windows

achrist at easystreet.com achrist at easystreet.com
Mon Aug 18 02:57:51 EDT 2003


I think that "wb" is obviously the correct format, and this is not
a bug.  CSV fields that contain an end of line within the field contain
a single character end-of-line marker (I can never remember whether 
this is \r or \n),  and this is not kosher for a Windows text file,
so it must be a binary file.


Al

Thomas Womack wrote:
> 
> I'm using the csv module in python 2.3 under Windows XP; it seems that
> two separate mechanisms try to handle the perverse Windows habit of
> ending lines with 0d0a, and so
> 
> writer = csv.writer(file('foo.csv','w'))
> for i in thing:
>   writer.write(i)
> 
> produces lines ending 0d0d0a, and when you load this into Excel 97 the
> data appears double-spaced.
> 
> Opening the file with 'wb' solves the problem, but it would be lovely
> were this either fixed or documented; it's rather unintuitive that a
> file opened with 'wb' still ends lines with 0d0a.
> 
> Please tell me if this is not the appropriate place to make this kind
> of bug report.
> 
> Tom




More information about the Python-list mailing list