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 examples can't close their files
Type: behavior Stage: patch review
Components: Documentation Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: docs@python Nosy List: SilentGhost, docs@python, eli.bendersky, ezio.melotti, georg.brandl, gwideman, ncoghlan, python-dev
Priority: normal Keywords: patch

Created on 2011-03-07 06:19 by gwideman, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue11426.1.patch eli.bendersky, 2011-03-11 07:27
Messages (9)
msg130228 - (view) Author: Graham Wideman (gwideman) Date: 2011-03-07 06:19
On the csv doc page  (.../library/csv.html) most of the examples show creation of an anonymous file object within the csv.reader or csv.writer function, for example...

spamWriter = csv.writer(open('eggs.csv', 'w'), delimiter=' ',....

This anonymity prevents later closing the file, which seems especially problematic for a writer.  It also confuses users as to whether there's some sort of close function on a csv.reader or csv.writer object which should be called, or perhaps some other magic behind the scenes.

I'm pretty sure that it's the doc that is incorrect here.  

This issue was raised pernthetically here http://bugs.python.org/issue7198#msg124678 by sjmachin, though mysteriously overlooked in his later suggested patch http://bugs.python.org/issue7198#msg126593

I suggest changing all examples to include the complete cycle of opening an explicit file, and later closing it.
msg130547 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-11 07:27
The attached patch tries to be true to the convention in other documentation pages, by using "with" in complete code samples (examples), but not using it in prompt (>>>) samples, where usage of "with" unnecessarily complicates interaction.
msg130569 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-03-11 13:39
Patch looks good to me.
The quotes are somewhat inconsistent (sometimes '' and sometimes ""), if you want you can "fix" them while you are at it.
msg130571 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-11 13:47
New changeset f2a73d65422a by Eli Bendersky in branch 'default':
Issue #11426: use 'with' statements on open files in CSV examples
http://hg.python.org/cpython/rev/f2a73d65422a
msg130572 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2011-03-11 13:51
Related issue #10461
msg130573 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-11 14:00
SilentGhost: yep, thanks for the reminder :)
msg130577 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-11 14:43
New changeset 4cb0a8f5c952 by Eli Bendersky in branch 'default':
Issue #11426: use 'with' statements on open files in CSV examples
http://hg.python.org/cpython/rev/4cb0a8f5c952

New changeset d54e9c4fcd43 by Eli Bendersky in branch '3.1':
Issue #11426: use 'with' statements on open files in CSV examples
http://hg.python.org/cpython/rev/d54e9c4fcd43
msg130700 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-03-12 22:33
This should be now fixed in 3.x, but not on 2.7.
msg130726 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-13 06:45
New changeset 52e1ad467edd by Eli Bendersky in branch '2.7':
Issue #11426: use 'with' statements on open files in CSV examples
http://hg.python.org/cpython/rev/52e1ad467edd
History
Date User Action Args
2022-04-11 14:57:14adminsetgithub: 55635
2011-03-13 06:45:38eli.benderskysetstatus: open -> closed
nosy: georg.brandl, ncoghlan, ezio.melotti, eli.bendersky, SilentGhost, docs@python, gwideman, python-dev
resolution: accepted
2011-03-13 06:45:10python-devsetnosy: georg.brandl, ncoghlan, ezio.melotti, eli.bendersky, SilentGhost, docs@python, gwideman, python-dev
messages: + msg130726
2011-03-12 22:33:28ezio.melottisetnosy: georg.brandl, ncoghlan, ezio.melotti, eli.bendersky, SilentGhost, docs@python, gwideman, python-dev
messages: + msg130700
2011-03-11 14:43:53python-devsetnosy: georg.brandl, ncoghlan, ezio.melotti, eli.bendersky, SilentGhost, docs@python, gwideman, python-dev
messages: + msg130577
2011-03-11 14:00:56eli.benderskysetnosy: georg.brandl, ncoghlan, ezio.melotti, eli.bendersky, SilentGhost, docs@python, gwideman, python-dev
messages: + msg130573
2011-03-11 13:51:16SilentGhostsetnosy: + SilentGhost
messages: + msg130572
2011-03-11 13:47:43python-devsetnosy: + python-dev
messages: + msg130571
2011-03-11 13:39:53ezio.melottisetnosy: georg.brandl, ncoghlan, ezio.melotti, eli.bendersky, docs@python, gwideman
messages: + msg130569
2011-03-11 07:27:36eli.benderskysetfiles: + issue11426.1.patch

nosy: + ezio.melotti, georg.brandl, ncoghlan
messages: + msg130547

keywords: + patch
stage: patch review
2011-03-07 11:19:45eli.benderskysetnosy: + eli.bendersky
2011-03-07 06:19:31gwidemancreate