警告过滤器忽略“一次”

2024-04-26 04:03:23 发布

您现在位置:Python中文网/ 问答频道 /正文

似乎我只能将警告模块设置为全部或无,我正在尝试确定原因

在我的脚本顶部,我使用了

warnings.simplefilter(action='once')warnings.simplefilter(action='ignore')

当我将操作设置为ignore时,它会按预期隐藏所有警告。但是,当我将操作设置为once时,它会在每次调用我的函数时打印警告(在循环中,从脚本中的另一个函数)。例:

/home/ec2-user/predict_evaluate/gt_ops.py:203: UserWarning: Too many positive examples of class {label} to balance dataset! Try increasing predict limit. warnings.warn(msg) /home/ec2-user/predict_evaluate/gt_ops.py:203: UserWarning: Too many positive examples of class {label} to balance dataset! Try increasing predict limit. warnings.warn(msg) /home/ec2-user/predict_evaluate/gt_ops.py:203: UserWarning: Too many positive examples of class {label} to balance dataset! Try increasing predict limit. warnings.warn(msg)

阻止action=once工作的原因是什么


Tags: pygt警告homeactionec2predictmany