我总是听到这个:
DeprecationWarning: integer argument expected, got float
我怎样才能让这条信息消失?在Python中有避免警告的方法吗?
我总是听到这个:
DeprecationWarning: integer argument expected, got float
我怎样才能让这条信息消失?在Python中有避免警告的方法吗?
当前回答
将实参转换为int。这很简单
int(argument)
其他回答
将实参转换为int。这很简单
int(argument)
我发现最干净的方法(特别是在windows上)是在C中添加以下代码:\Python26\Lib\site-packages\sitecustomize.py:
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
注意,我必须创建这个文件。当然,如果您的路径不同,请将路径更改为python。
码头工人的解决方案
在运行python应用程序之前禁用ALL警告 您也可以禁用dockerized测试
ENV PYTHONWARNINGS="ignore::DeprecationWarning"
传递正确的参数?: P
更严重的是,您可以在命令行中将参数-Wi::DeprecationWarning传递给解释器,以忽略弃用警告。
你应该修改你的代码,但以防万一,
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)