@contextlib.contextmanager
def silence():
 old_stdout = sys.stdout
 old_stderr = sys.stderr
 sys.stdout = _DummyFile()
 sys.stderr = _DummyFile()
 (yield)
 sys.stdout = old_stdout
 sys.stderr = old_stderr

@ contextlib . contextmanager def silence ( ) : old_stdout = sys . stdout old_stderr = sys . stderr sys . stdout = _DummyFile ( ) sys . stderr = _DummyFile ( ) ( yield ) sys . stdout = old_stdout sys . stderr = old_stderr
a context manager that silences sys .