mirror of
https://github.com/python/cpython.git
synced 2025-10-01 21:02:15 +00:00
[3.12] gh-111282: Fix NamedTemporaryFile example code (GH-111283) (GH-111579)
(cherry picked from commit 102685c4c8
)
Co-authored-by: Krzysiek Karbowiak <krzysztof.karbowiak@interia.pl>
This commit is contained in:
parent
ec00397912
commit
21c8fbf28d
1 changed files with 7 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue