diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-05-26 14:34:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-26 14:34:22 (GMT) |
commit | 1261941e02cd04829592b1b1360b4ec21bfcdb9a (patch) | |
tree | 92f1de2e61a0e72dc756d28dfe953d32a9cd7e94 /Doc/library | |
parent | 7b3b6982a5683f5146ede58a448d3edb777e501b (diff) | |
download | cpython-1261941e02cd04829592b1b1360b4ec21bfcdb9a.zip cpython-1261941e02cd04829592b1b1360b4ec21bfcdb9a.tar.gz cpython-1261941e02cd04829592b1b1360b4ec21bfcdb9a.tar.bz2 |
bpo-41147: [doc] contextlib.redirect_stdout() provides the new stream as context var (GH-21199) (GH-26379)
(cherry picked from commit 46db39d7bd67fb9fea133cd4f18cdf7eacb0f6d9)
Co-authored-by: Peter Law <PeterJCLaw@gmail.com>
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/contextlib.rst | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst index dd903ce..42834fe 100644 --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -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() |