Skip to content

Update open() docs with link to File Tutorial#21737

Merged
methane merged 3 commits into
python:masterfrom
bbkane:master
Aug 8, 2020
Merged

Update open() docs with link to File Tutorial#21737
methane merged 3 commits into
python:masterfrom
bbkane:master

Conversation

@bbkane
Copy link
Copy Markdown
Contributor

@bbkane bbkane commented Aug 4, 2020

Add a link to the "Reading and Writing Files" page so users can
more easily discover how file handles are handled with the with
context manager vs without it.

Adds a link to the "Reading and Writing Files" page so users can
more easily discover how file handles are handled with the `with`
context manager vs without it.
@methane
Copy link
Copy Markdown
Member

methane commented Aug 5, 2020

Please don't use the term "file handle".

@bbkane
Copy link
Copy Markdown
Contributor Author

bbkane commented Aug 5, 2020

Thanks for the comment @methane ! I've changed the wording from "file handle" to "file object" (the same phrasing in https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files ).

Happy to change it again if you will give me more context for your comment.

@methane
Copy link
Copy Markdown
Member

methane commented Aug 6, 2020

I am not sure See :ref:tut-files for file object details. is good reference. open document has this paragraph.

The type of file object returned by the open() function depends on the mode. When open() is used to open a file in a text mode ('w', 'r', 'wt', 'rt', etc.), it returns a subclass of io.TextIOBase (specifically io.TextIOWrapper). When used to open a file in a binary mode with buffering, the returned class is a subclass of io.BufferedIOBase. The exact class varies: in read binary mode, it returns an io.BufferedReader; in write binary and append binary modes, it returns an io.BufferedWriter, and in read/write mode, it returns an io.BufferedRandom. When buffering is disabled, the raw stream, a subclass of io.RawIOBase, io.FileIO, is returned.

I think tut-files is not for "file object details", because io module document is "file object details".

Could you suggest better phrasing for "tutorial"?

@bbkane
Copy link
Copy Markdown
Contributor Author

bbkane commented Aug 6, 2020

When I first read the open() docs, i didn't know how or when the file would be closed, I just knew people told me to use with. The point of this change is to bring reference of the way file objects are handled closer to the open() docs for new users.

Maybe I could change the sentence to:

See :ref:tut-files for more examples of how to use this function.

Once built, this will show to the user:

See Reading and Writing Files for more examples of how to use this function.

@bbkane
Copy link
Copy Markdown
Contributor Author

bbkane commented Aug 6, 2020

Since the Reading and Writing Files tutorial page contains documentation on how & when to use the with keyword with open, I felt it was the best page to link to in order to provide clarity. This page also links back to the open() docs, so they'll be linking to each other.

Do you prefer this new phrasing?

@methane
Copy link
Copy Markdown
Member

methane commented Aug 7, 2020

Do you prefer this new phrasing?

I prefere new phrasing to old one.

Other option is "for tutorial", because people may expect "more examples for more complex use cases" when they see "more examples".
But I am not sure "for tutoraial" is natural English.

@bbkane
Copy link
Copy Markdown
Contributor Author

bbkane commented Aug 7, 2020

@methane , I've changed my PR to the "more examples" option. I think it's a tad more clear and you seem to like it too. Please merge if you have no further concerns.

@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @bbkane for the PR, and @methane for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 8, 2020
Adds a link to the "Reading and Writing Files" page so users can
more easily discover how file handles are handled with the `with`
context manager vs without it.
(cherry picked from commit 705f145)

Co-authored-by: Benjamin Kane <bbkane@users.noreply.github.com>
@bedevere-bot
Copy link
Copy Markdown

GH-21780 is a backport of this pull request to the 3.9 branch.

@bedevere-bot
Copy link
Copy Markdown

GH-21781 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 8, 2020
Adds a link to the "Reading and Writing Files" page so users can
more easily discover how file handles are handled with the `with`
context manager vs without it.
(cherry picked from commit 705f145)

Co-authored-by: Benjamin Kane <bbkane@users.noreply.github.com>
miss-islington added a commit that referenced this pull request Aug 8, 2020
Adds a link to the "Reading and Writing Files" page so users can
more easily discover how file handles are handled with the `with`
context manager vs without it.
(cherry picked from commit 705f145)

Co-authored-by: Benjamin Kane <bbkane@users.noreply.github.com>
miss-islington added a commit that referenced this pull request Aug 8, 2020
Adds a link to the "Reading and Writing Files" page so users can
more easily discover how file handles are handled with the `with`
context manager vs without it.
(cherry picked from commit 705f145)

Co-authored-by: Benjamin Kane <bbkane@users.noreply.github.com>
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Aug 20, 2020
Adds a link to the "Reading and Writing Files" page so users can
more easily discover how file handles are handled with the `with`
context manager vs without it.
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
Adds a link to the "Reading and Writing Files" page so users can
more easily discover how file handles are handled with the `with`
context manager vs without it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip issue skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants