classification
Title: use universal newline mode in csv module examples
Type: enhancement Stage: needs patch
Components: Documentation Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, georg.brandl, r.david.murray, sfinnie, terry.reedy
Priority: normal Keywords:

Created on 2010-04-13 21:11 by sfinnie, last changed 2011-03-19 19:11 by skip.montanaro.

Messages (3)
msg103086 - (view) Author: (sfinnie) Date: 2010-04-13 21:11
Running the examples in the csv module docs (http://docs.python.org/library/csv.html) causes problems reading file on a mac.  This is highlighted in issue 1072404 (http://bugs.python.org/issue1072404).

Commentary on the bug indicates a no fix, meaning most/many people using a mac will get an error if they use the sample code in the docs.

A simpler solution would be to use universal newline mode in the doc examples.  This is actually mentioned in commentary on the bug, and appears to work.

Proposal
--------
In all example code blocks, use mode 'rU' when opening the file.  1st code block, for example, would become:

spamReader = csv.reader(open('eggs.csv', 'rU'), delimiter=' ', quotechar='|')

That should solve the problem on mac without impacting compatibility on other operating systems.  Note: Haven't been able to verify this on other platforms.
msg113190 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-07 18:51
In the current 2.7 docs, files are opened with 'rb' or 'wb'.
In msg106210 of #1072404, RDM says "The doc has been fixed;".
I am not sure if this refers a change in the open or just removal of reference to non-working delimiter option.
David?
Any opinion on this request?
msg113221 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-08 01:00
"The doc has been fixed" refers to the fact that the lineterminator dialect option is now documented as applying only to writing, not to reading.

The docs could certainly be improved to discuss using universal newline mode.  I'm not clear on whether or not there are disadvantages to using universal newline mode with the py2 version of the csv module, but I wouldn't be surprised if there are.  Perhaps Skip can comment on whether changing the examples to use rU would be a good idea or not.

Note that the situation for the py3k csv module is different, and it would be helpful if someone could test this issue there.  Though in truth we have no resources to support non-OSX macs any longer, so if it doesn't work it may be just tough luck.
History
Date User Action Args
2011-03-19 19:11:45skip.montanarosetnosy: - skip.montanaro
2010-08-08 01:00:09r.david.murraysetnosy: + skip.montanaro
messages: + msg113221
2010-08-07 18:51:30terry.reedysetversions: - Python 2.6
nosy: + terry.reedy, r.david.murray, docs@python

messages: + msg113190

assignee: georg.brandl -> docs@python
stage: needs patch
2010-07-11 02:00:59terry.reedysetversions: + Python 3.1, Python 3.2
2010-04-13 21:11:23sfinniecreate