gpt4 book ai didi

python - 忽略消息包含特定字符串的警告

转载 作者:行者123 更新时间:2023-12-05 00:54:42 25 4
gpt4 key购买 nike

我不希望打印消息中包含“属性”的警告。我知道我可以通过指定整个消息来忽略警告:

import warnings

warnings.filterwarnings("ignore", message="All message displayed in console.")

我需要类似的东西:

warnings.filterwarnings("ignore", message="*property*")

我也知道我可以通过以下方式禁用代码特定部分的警告:

import warnings

with warnings.catch_warnings():
warnings.simplefilter("ignore")
function_that_causes_warnings()

最佳答案

filterwarningsmessage 参数是一个正则表达式,因此你应该可以使用

warnings.filterwarnings("ignore", message=".*property.*")

其中 .* 匹配零次或多次出现的任何字符。

关于python - 忽略消息包含特定字符串的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65761137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com