John Machin <[email protected]> added the comment:
Please re-open this. The binary/text mode problem still exists with Python 3.X
on Windows. Quite simply, there is no option available to the caller to open
the output file in binary mode, because the module is throwing str objects at
the file. The module's idea of "taking control" in the default case appears to
be to write \r\n which is then processed by the Windows runtime and becomes
\r\r\n.
Python 3.1.3 (r313:86834, Nov 27 2010, 18:30:53) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> f = open('terminator31.csv', 'w')
>>> row = ['foo', None, 3.14159]
>>> writer = csv.writer(f)
>>> writer.writerow(row)
14
>>> writer.writerow(row)
14
>>> f.close()
>>> open('terminator31.csv', 'rb').read()
b'foo,,3.14159\r\r\nfoo,,3.14159\r\r\n'
>>>
And it's not just a row terminator problem; newlines embedded in fields are
likewise expanded to \r\n by the Windows runtime.
----------
nosy: +sjmachin
versions: +Python 3.1 -Python 2.6
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue7198>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com