]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41147: [doc] contextlib.redirect_stdout() provides the new stream as context...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 26 May 2021 14:43:37 +0000 (07:43 -0700)
committerGitHub <noreply@github.com>
Wed, 26 May 2021 14:43:37 +0000 (15:43 +0100)
(cherry picked from commit 46db39d7bd67fb9fea133cd4f18cdf7eacb0f6d9)

Co-authored-by: Peter Law <PeterJCLaw@gmail.com>
Doc/library/contextlib.rst

index aa848df8c42903c1b38a425aa6b356f35570ec77..3dcedf72a390ee52f3117cd659c9e83286929c8b 100644 (file)
@@ -236,10 +236,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()