我正在使用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但是它不会静默所有类型的输出,我怎么能静默所有类型呢?
发布于 2021-04-08 20:45:11
我怀疑您使用的是类似IPython的环境,例如Jupyter notebook。然后,您可以在单元格中使用%%capture magic command。
例如,
%%capture
output = do_some_verbose_things(args)默认情况下,它还会捕获stderr,我认为您看到的输出都在那里。
https://stackoverflow.com/questions/67003595
复制相似问题