Skip to content

Commit af01958

Browse files
committed
Add discard/suppress example
1 parent 485415e commit af01958

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Doc/library/contextlib.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ Functions and classes provided:
356356
with redirect_stdout(sys.stderr):
357357
help(pow)
358358

359+
To discard or suppress the output of :func:`help` without collecting the data::
360+
361+
with open(os.devnull, 'w') as devnull:
362+
with redirect_stdout(devnull):
363+
help(pow)
364+
359365
Note that the global side effect on :data:`sys.stdout` means that this
360366
context manager is not suitable for use in library code and most threaded
361367
applications. It also has no effect on the output of subprocesses.

0 commit comments

Comments
 (0)