Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Doc/library/contextlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,12 @@ Functions and classes provided:
.. function:: redirect_stdout(new_target)

Context manager for temporarily redirecting :data:`sys.stdout` to
another file or file-like object.
another :term:`file object`.

This tool adds flexibility to existing functions or classes whose output
is hardwired to stdout.
is hardwired to :data:`sys.stdout`. This does not modify underlying file
objects or file descriptors. It sets the global :data:`sys.stdout` to the
provided value and at context exit sets it to the previous value.

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
Expand Down Expand Up @@ -366,8 +368,9 @@ Functions and classes provided:

.. function:: redirect_stderr(new_target)

Similar to :func:`~contextlib.redirect_stdout` but redirecting
:data:`sys.stderr` to another file or file-like object.
Similar to :func:`~contextlib.redirect_stdout` but redirecting the global
:data:`sys.stderr` to another value, typically a :term:`file object`
returned from :func:`open`.

This context manager is :ref:`reentrant <reentrant-cms>`.

Expand Down
Loading