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 e7078ee commit bee66d3Copy full SHA for bee66d3
Doc/library/contextlib.rst
@@ -236,10 +236,11 @@ Functions and classes provided:
236
237
For example, the output of :func:`help` normally is sent to *sys.stdout*.
238
You can capture that output in a string by redirecting the output to an
239
- :class:`io.StringIO` object::
+ :class:`io.StringIO` object. The replacement stream is returned from the
240
+ ``__enter__`` method and so is available as the target of the
241
+ :keyword:`with` statement::
242
- f = io.StringIO()
- with redirect_stdout(f):
243
+ with redirect_stdout(io.StringIO()) as f:
244
help(pow)
245
s = f.getvalue()
246
0 commit comments