slight csv misbehavior under Windows

T

Thomas Womack

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
 
A

achrist

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top