[issue7198] Extraneous newlines with csv.writer on Windows

Skip Montanaro report at bugs.python.org
Thu Jul 29 13:10:57 CEST 2010


Skip Montanaro <skip at pobox.com> added the comment:

> If the documentation is not clear enough about requiring binary, it is
    > a doc bug.

The documentation for both csv.reader and csv.writer state (this is from the
Python 2.7 version):

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

I suppose we could be explicit and mention Windows here, but the wording is
quite clear.  There is really no harm in always opening the file in binary
mode, and I do that myself even though I only program on Unix or Mac
platforms where it's safe to open the file in text mode.

This all changed in Python 3.  There, the choice of line ending is up to the
programmer, so file objects for use by the csv module are opened with
newline='' and when writing CSV data the writer object takes complete
control of proper line termination according to the programmer's stated
choice of lineterminator.

Skip

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7198>
_______________________________________


More information about the Python-bugs-list mailing list