我正在使用 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 的环境,例如木星笔记本。然后你可以使用 %%capture
magic command在一个单元格中。
例如,
%%capture
output = do_some_verbose_things(args)
默认情况下,它还会捕获 stderr
,我认为您看到的输出会在那里。
https://stackoverflow.com/questions/67003595/
相关文章:
validation - VeeValidate 4 : two forms on one page
ios - FaSTLane 设置 - 致命 : could not read Password f
google-apps-script - 在多个工作表中搜索一个词
java - 在 Spring Cloud Gateway 中获取真实的客户端 IP 地址
azure - 对于高级、低延迟、带有搜索功能的大量小型 json 文件,Azure BlockBl
typescript - 类型错误 : Property 'currentTime' does no
javascript - 如果没有 .js 扩展名,则为 ERR_MODULE_NOT_FOUND
sql-server - SQL 服务器 : splitting a row into severa