我不希望警告信息中包含"property"待印。我知道我可以通过使用
指定其整个消息来忽略警告: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()
filterwarnings
的消息参数是一个正则表达式,因此您应该能够使用
warnings.filterwarnings("ignore", message=".*property.*")
其中.*
匹配0个或多个字符。