我总是听到这个:
DeprecationWarning: integer argument expected, got float
我怎样才能让这条信息消失?在Python中有避免警告的方法吗?
我总是听到这个:
DeprecationWarning: integer argument expected, got float
我怎样才能让这条信息消失?在Python中有避免警告的方法吗?
当前回答
将实参转换为int。这很简单
int(argument)
其他回答
对于python 3,只需编写下面的代码来忽略所有警告。
from warnings import filterwarnings
filterwarnings("ignore")
你应该修改你的代码,但以防万一,
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
来自警告模块的文档:
#!/usr/bin/env python -W ignore::DeprecationWarning
如果你在Windows上:传递-W ignore::DeprecationWarning作为Python的参数。不过更好的解决方法是强制转换为int类型。
(注意,在Python 3.2中,默认情况下会忽略弃用警告。)
Python 3
在编写代码之前,只需在下面写下容易记住的行:
import warnings
warnings.filterwarnings("ignore")
码头工人的解决方案
在运行python应用程序之前禁用ALL警告 您也可以禁用dockerized测试
ENV PYTHONWARNINGS="ignore::DeprecationWarning"