We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 156699b commit 46db39dCopy full SHA for 46db39d
Doc/library/contextlib.rst
@@ -312,10 +312,11 @@ Functions and classes provided:
312
313
For example, the output of :func:`help` normally is sent to *sys.stdout*.
314
You can capture that output in a string by redirecting the output to an
315
- :class:`io.StringIO` object::
+ :class:`io.StringIO` object. The replacement stream is returned from the
316
+ ``__enter__`` method and so is available as the target of the
317
+ :keyword:`with` statement::
318
- f = io.StringIO()
- with redirect_stdout(f):
319
+ with redirect_stdout(io.StringIO()) as f:
320
help(pow)
321
s = f.getvalue()
322
0 commit comments