gh-111282: Fix NamedTemporaryFile example code (GH-111283)

This commit is contained in:
Krzysiek Karbowiak 2023-10-31 23:06:02 +01:00 committed by GitHub
parent 770530679e
commit 102685c4c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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