Skip to content

Commit 21c8fbf

Browse files
[3.12] gh-111282: Fix NamedTemporaryFile example code (GH-111283) (GH-111579)
(cherry picked from commit 102685c) Co-authored-by: Krzysiek Karbowiak <[email protected]>
1 parent ec00397 commit 21c8fbf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Doc/library/tempfile.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,13 @@ Here are some examples of typical usage of the :mod:`tempfile` module::
404404

405405
# create a temporary file using a context manager
406406
# close the file, use the name to open the file again
407-
>>> with tempfile.TemporaryFile(delete_on_close=False) as fp:
408-
... fp.write(b'Hello world!')
409-
... fp.close()
410-
# the file is closed, but not removed
411-
# open the file again by using its name
412-
... with open(fp.name) as f
413-
... f.read()
407+
>>> with tempfile.NamedTemporaryFile(delete_on_close=False) as fp:
408+
... fp.write(b'Hello world!')
409+
... fp.close()
410+
... # the file is closed, but not removed
411+
... # open the file again by using its name
412+
... with open(fp.name, mode='rb') as f:
413+
... f.read()
414414
b'Hello world!'
415415
>>>
416416
# file is now removed

0 commit comments

Comments
 (0)