]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41147: [doc] contextlib.redirect_stdout() provides the new stream as context...
authorPeter Law <PeterJCLaw@gmail.com>
Wed, 26 May 2021 14:13:09 +0000 (15:13 +0100)
committerGitHub <noreply@github.com>
Wed, 26 May 2021 14:13:09 +0000 (15:13 +0100)
Doc/library/contextlib.rst

index dd903ce8ee9165666a73905218b4e6fcacebbd70..42834fe68bfaeef94ac8b57ea79cd6724d1461c6 100644 (file)
@@ -312,10 +312,11 @@ Functions and classes provided:
 
    For example, the output of :func:`help` normally is sent to *sys.stdout*.
    You can capture that output in a string by redirecting the output to an
-   :class:`io.StringIO` object::
+   :class:`io.StringIO` object. The replacement stream is returned from the
+   ``__enter__`` method and so is available as the target of the
+   :keyword:`with` statement::
 
-        f = io.StringIO()
-        with redirect_stdout(f):
+        with redirect_stdout(io.StringIO()) as f:
             help(pow)
         s = f.getvalue()