diff options
author | Peter Law <PeterJCLaw@gmail.com> | 2021-05-26 14:13:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-26 14:13:09 (GMT) |
commit | 46db39d7bd67fb9fea133cd4f18cdf7eacb0f6d9 (patch) | |
tree | acad7d15aeacd81a59dfcd5b9463f50221e57d5b /Doc/library/contextlib.rst | |
parent | 156699bca02dd2def844d03e26fc16a831336635 (diff) | |
download | cpython-46db39d7bd67fb9fea133cd4f18cdf7eacb0f6d9.zip cpython-46db39d7bd67fb9fea133cd4f18cdf7eacb0f6d9.tar.gz cpython-46db39d7bd67fb9fea133cd4f18cdf7eacb0f6d9.tar.bz2 |
bpo-41147: [doc] contextlib.redirect_stdout() provides the new stream as context var (GH-21199)
Diffstat (limited to 'Doc/library/contextlib.rst')
-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() |