mirror of
https://github.com/python/cpython.git
synced 2025-10-02 05:12:23 +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,12 +404,12 @@ Here are some examples of typical usage of the :mod:`tempfile` module::
|
||||||
|
|
||||||
# create a temporary file using a context manager
|
# create a temporary file using a context manager
|
||||||
# close the file, use the name to open the file again
|
# close the file, use the name to open the file again
|
||||||
>>> with tempfile.TemporaryFile(delete_on_close=False) as fp:
|
>>> with tempfile.NamedTemporaryFile(delete_on_close=False) as fp:
|
||||||
... fp.write(b'Hello world!')
|
... fp.write(b'Hello world!')
|
||||||
... fp.close()
|
... fp.close()
|
||||||
# the file is closed, but not removed
|
... # the file is closed, but not removed
|
||||||
# open the file again by using its name
|
... # open the file again by using its name
|
||||||
... with open(fp.name) as f
|
... with open(fp.name, mode='rb') as f:
|
||||||
... f.read()
|
... f.read()
|
||||||
b'Hello world!'
|
b'Hello world!'
|
||||||
>>>
|
>>>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue