根据Python文档,我可以传递多个警告过滤器:
当在一行上列出多个过滤器时(如 PYTHONWARNINGS),各个过滤器用逗号分隔
但当我尝试这样做时,Python 抱怨它忽略了无效选项。在这里,我试图通过always::::并且error::RuntimeWarning:::
$ python -W 'always::::,error::RuntimeWarning::' -c "print('hello, world')"
Invalid -W option ignored: too many fields (max 5): 'always::::,error::RuntimeWarning::'
Run Code Online (Sandbox Code Playgroud)
如果我跑的话它会起作用
PYTHONWARNINGS="always::::,error::RuntimeWarning::" python -c "print('hello, world')"
Run Code Online (Sandbox Code Playgroud)
但是将其作为命令行标志传递的语法是什么?
小智 -1
尝试将以下内容添加到您的脚本中
import warnings
warnings.filterwarnings("ignore")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1204 次 |
| 最近记录: |