提问人:Gerry 提问时间:3/21/2021 更新时间:3/21/2021 访问量:2926
warnings.filterwarnings(“ignore”) 不会忽略 logging.warning
warnings.filterwarnings("ignore") doesn't ignore logging.warning
问:
我想知道为什么不能忽略所有警告消息。这里有什么要求吗?warnings.filterwarnings("ignore")
>>> import logging
>>> import warnings
>>> warnings.filterwarnings("ignore")
>>> logging.warn("This should not be printed")
WARNING:root:This should not be printed
>>>
答:
2赞
avayert
3/21/2021
#1
模块和模块有意分开的过滤器。如果要过滤掉模块中的警告消息,则必须使用模块中的相应功能,例如过滤器或适当的调用。warning
logging
logging
logging
setLevel
评论
1赞
Gerry
3/21/2021
谢谢@avayert。你能举一个简单的例子吗?
评论