]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111282: Fix NamedTemporaryFile example code (GH-111283)
authorKrzysiek Karbowiak <krzysztof.karbowiak@interia.pl>
Tue, 31 Oct 2023 22:06:02 +0000 (23:06 +0100)
committerGitHub <noreply@github.com>
Tue, 31 Oct 2023 22:06:02 +0000 (17:06 -0500)
Doc/library/tempfile.rst

index b2baa54d9522df65bd83791c26377bba2e845706..b68a78e8267bccbb75505a8dff952e19ccaf638a 100644 (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