mirror of
https://github.com/python/cpython
synced 2024-10-14 23:49:42 +00:00
gh-111282: Fix NamedTemporaryFile example code (GH-111283)
This commit is contained in:
parent
770530679e
commit
102685c4c8
|
@ -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…
Reference in a new issue