Skip to content

[3.12] gh-111282: Fix NamedTemporaryFile example code (GH-111283) #111579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Doc/library/tempfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,13 @@ Here are some examples of typical usage of the :mod:`tempfile` module::

# create a temporary file using a context manager
# close the file, use the name to open the file again
>>> with tempfile.TemporaryFile(delete_on_close=False) as fp:
... fp.write(b'Hello world!')
... fp.close()
# the file is closed, but not removed
# open the file again by using its name
... with open(fp.name) as f
... f.read()
>>> with tempfile.NamedTemporaryFile(delete_on_close=False) as fp:
... fp.write(b'Hello world!')
... fp.close()
... # the file is closed, but not removed
... # open the file again by using its name
... with open(fp.name, mode='rb') as f:
... f.read()
b'Hello world!'
>>>
# file is now removed
Expand Down