def quiet():
# save stdout/stderr
# Jupyter doesn't support setting it back to
# sys.__stdout__ and sys.__stderr__
_sys_stdout = sys.stdout
_sys_stderr = sys.stderr
# Divert stdout and stderr to devnull
sys.stdout = sys.stderr = open(os.devnull, "w")
try:
yield
finally:
# Revert back to standard stdout/stderr
sys.stdout = _sys_stdout
sys.stderr = _sys_stderr
评论列表
文章目录