On Fri, May 12, 2017 at 8:03 PM, Peter Otten <__pete...@web.de> wrote:
> I don't have a Windows system to test, but doesn't that mean that on Windows
>
> with open("tmp.csv", "w") as f:
>     csv.writer(f).writerows([["one"], ["two"]])
> with open("tmp.csv", "rb") as f:
>     print(f.read())
>
> would produce
>
> b"one\r\r\ntwo\r\r\n"
>
> ? How is that avoided?

Python 3 doesn't use the platform's standard I/O implementation.
However, it tries to be consistent with the platform by using
os.linesep as the default for translating newlines. That's not
necessarily compatible with the csv module, so it requires disabling
newline translation by passing newline="" to open(). Otherwise it does
cause the problem that you suppose it would, which is documented:

https://docs.python.org/3/library/csv.html#csv.writer
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to