我正在使用Prophet(Facebook的时间序列库),它能产生大量的输出。大概是这样的: Prophet output
我已经对这样的输出保持沉默:
@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = old_stdout
但它并没有使所有类型的输出都静音,我怎么能使所有类型的输出都静音呢
我怀疑您正在使用类似IPython的环境,例如Jupyter笔记本。然后可以在单元格中使用
%%capture
magic command比如说,
默认情况下,它还捕获了
stderr
,我认为您看到的输出将在那里进行相关问题 更多 >
编程相关推荐