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: Reorder 'with' statement for files in Python Tutorial
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Mariatta, akuchling, berker.peksag, chris.jerdonek, ezio.melotti, georg.brandl, jjalocha
Priority: low Keywords:

Created on 2009-07-19 01:19 by jjalocha, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue6519.txt akuchling, 2016-11-06 19:44 review
Pull Requests
URL Status Linked Edit
PR 2143 merged akuchling, 2017-06-13 01:11
PR 2145 merged Mariatta, 2017-06-13 05:36
PR 2146 merged Mariatta, 2017-06-13 05:36
Messages (10)
msg90698 - (view) Author: Jerzy Jalocha N (jjalocha) Date: 2009-07-19 01:19
Actually, the Python Tutorial recommends the use of the 'with' statement
in Section 7.2.1. "Methods of File Objects":

> It is good practice to use the with keyword when dealing with file
> objects. [etc.]

But the example and description are at the very bottom of this very
large section, and are easily missed by new Python users.

If this suggestion is to be taken seriously, I suggest putting this
information at a more prominent place, somewhere at the top of the short
section 7.2. "Reading and Writing Files".
msg100179 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-27 09:48
All the examples there assume that "a file object called f has already been created". Using a 'with' there it's not a good idea because the users will have to keep the instructions indented under the 'with'.
However I agree that it would be better to move that example earlier. Maybe in 7.2 both the forms can be shown and discussed briefly.
msg280167 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2016-11-06 19:44
Good suggestion -- here's a patch that moves it and rewrites a little.
msg280208 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-11-07 16:41
The patch looks good to me. I think we can tweak the content a bit. I left some comments on Rietveld.

Thanks!
msg295825 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-06-12 20:43
@akuchling Can you prepare a PR on GitHub?
msg295832 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2017-06-13 01:11
PR filed against master: https://github.com/python/cpython/pull/2143
msg295847 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-06-13 05:31
New changeset bd4e9e0ca96dabf33605d9b1fd1e0562ece8ae18 by Mariatta (Andrew Kuchling) in branch 'master':
bpo-6519: Improve Python Input Output Tutorial (GH-2143)
https://github.com/python/cpython/commit/bd4e9e0ca96dabf33605d9b1fd1e0562ece8ae18
msg295848 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-06-13 05:40
New changeset 81c05ccc10d044584dff3a69ee531094ed76ee2c by Mariatta in branch '3.6':
bpo-6519: Improve Python Input Output Tutorial (GH-2143) (GH-2145)
https://github.com/python/cpython/commit/81c05ccc10d044584dff3a69ee531094ed76ee2c
msg295849 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-06-13 05:40
New changeset 5a86154a931083e6a9f9bdf9cc8b3bc33abb673d by Mariatta in branch '3.5':
bpo-6519: Improve Python Input Output Tutorial (GH-2143) (GH-2146)
https://github.com/python/cpython/commit/5a86154a931083e6a9f9bdf9cc8b3bc33abb673d
msg295850 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-06-13 05:43
Thanks everyone!
I merged the PR and backported to 3.6 and 3.5.

There are a bunch of conflicts when trying to backport to 2.7, so I decided not to bother.
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50768
2017-06-13 05:43:24Mariattasetstatus: open -> closed
versions: - Python 2.7
messages: + msg295850

resolution: fixed
stage: patch review -> resolved
2017-06-13 05:40:45Mariattasetmessages: + msg295849
2017-06-13 05:40:20Mariattasetmessages: + msg295848
2017-06-13 05:36:09Mariattasetpull_requests: + pull_request2196
2017-06-13 05:36:02Mariattasetpull_requests: + pull_request2195
2017-06-13 05:31:03Mariattasetmessages: + msg295847
2017-06-13 01:11:41akuchlingsetmessages: + msg295832
pull_requests: + pull_request2193
2017-06-12 20:43:27Mariattasetnosy: + Mariatta
messages: + msg295825
2016-11-07 16:41:34berker.peksagsetversions: + Python 2.7
2016-11-07 16:41:11berker.peksagsetversions: + Python 3.5, Python 3.6, Python 3.7, - Python 2.7, Python 3.2, Python 3.3, Python 3.4
nosy: + berker.peksag

messages: + msg280208

stage: needs patch -> patch review
2016-11-06 19:44:51akuchlingsetfiles: + issue6519.txt
nosy: + akuchling
messages: + msg280167

2012-09-26 17:12:32ezio.melottisetnosy: + chris.jerdonek

versions: + Python 3.3, Python 3.4, - Python 3.1
2010-10-29 10:07:21adminsetassignee: georg.brandl -> docs@python
2010-08-07 21:28:34terry.reedysetversions: - Python 2.6
2010-02-27 09:48:49ezio.melottisetstage: needs patch
messages: + msg100179
versions: - Python 3.0
2009-08-10 11:49:32ezio.melottisetpriority: low
nosy: + ezio.melotti
2009-07-19 01:19:28jjalochacreate