Skip to content

Commit

Permalink
pythongh-111282: Fix NamedTemporaryFile example code (pythonGH-111283)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkarbowiak committed Oct 31, 2023
1 parent 7705306 commit 102685c
Showing 1 changed file with 7 additions and 7 deletions.
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

0 comments on commit 102685c

Please sign in to comment.