bpo-41147: [doc] contextlib.redirect_stdout() provides the new stream as context var (GH-21199)

This commit is contained in:
Peter Law 2021-05-26 15:13:09 +01:00 committed by GitHub
parent 156699bca0
commit 46db39d7bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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()