我总是听到这个:

DeprecationWarning: integer argument expected, got float

我怎样才能让这条信息消失?在Python中有避免警告的方法吗?


当前回答

我发现最干净的方法(特别是在windows上)是在C中添加以下代码:\Python26\Lib\site-packages\sitecustomize.py:

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

注意,我必须创建这个文件。当然,如果您的路径不同,请将路径更改为python。

其他回答

对于python 3,只需编写下面的代码来忽略所有警告。

from warnings import filterwarnings
filterwarnings("ignore")

我发现最干净的方法(特别是在windows上)是在C中添加以下代码:\Python26\Lib\site-packages\sitecustomize.py:

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

注意,我必须创建这个文件。当然,如果您的路径不同,请将路径更改为python。

你应该修改你的代码,但以防万一,

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning) 

有点粗糙,但它为我工作后,上述方法没有。

- myscrypt。py 2 > / dev /空

如果你知道你在做什么,另一种方法是简单地找到警告你的文件(文件的路径显示在警告信息中),注释生成警告的行。