Skip to content

Commit

Permalink
bpo-41147: [doc] contextlib.redirect_stdout() provides the new stream…
Browse files Browse the repository at this point in the history
… as context var (GH-21199) (GH-26379)

(cherry picked from commit 46db39d)

Co-authored-by: Peter Law <[email protected]>
  • Loading branch information
miss-islington and PeterJCLaw authored May 26, 2021
1 parent 7b3b698 commit 1261941
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Doc/library/contextlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 1261941

Please sign in to comment.