This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: CSV, builtin open(), newline arg. Docs broken again.
Type: behavior Stage:
Components: Documentation Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, gwideman, r.david.murray
Priority: normal Keywords:

Created on 2013-10-01 07:14 by gwideman, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg198752 - (view) Author: Graham Wideman (gwideman) Date: 2013-10-01 07:14
The docs appear to be incorrect for CSV at: http://docs.python.org/3.3/library/csv.html.

Per issue http://bugs.python.org/issue7198 , there's a long history of contention between os.open and csv.writer, in which, on Windows, the default result is an unwanted additional '\r'. That was 'fixed' by using the newline='' argument to open(). 

This is reflected in the docs at the above link:

with open('eggs.csv', 'w', newline='') as csvfile:
    spamwriter = csv.writer(csvfile, delimiter=...)

However, in python 3.3.2 use of the newline argument returns: "TypeError: 'newline' is an invalid keyword argument for this function."

In brief testing, it appears that a correct result can be obtain by calling open as follows:

with open(somepath, 'wb') as writerfile: 
    writer = csv.writer(writerfile, delimiter=...)

Note: binary mode, not text as previously needed and currently documented.
msg198778 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-10-01 13:54
You must have a different 'open' in your namespace when you execute that.  Dropping a keyword argument like that is something we would never do without a deprecation period.

Your example works fine for me.
msg198810 - (view) Author: Graham Wideman (gwideman) Date: 2013-10-01 22:01
David:
Yes, as it turns out you are absolutely right, in a manner of speaking.  I have retested this exhaustively today, and here's the root cause.

It turns out that in testing, I must have activate a particular simplified test script by invoking only scriptname.py rather than invoking 'python scriptname.py'. (And then repeating that mistake by reinvoking via console history... doh!)

The latter reliably invokes python 3.3.2, because that's the only python in my PATH.  The former, it turns out, invokes the Windows Python Launcher, which finds a previously installed Python 2.7.1, despite that not being on the PATH. 

So, in my mind, the possibility of launching any version other than Python 3.3.2 did not enter the picture.

Prior to this, I was only vaguely aware that Windows Python Launcher existed. Ironically, it was probably installed by Python 3.3.2.

Sorry for the bogus bug alert.
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63335
2013-10-01 22:01:08gwidemansetmessages: + msg198810
2013-10-01 13:54:05r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg198778

resolution: not a bug
2013-10-01 07:14:23gwidemancreate