我总是听到这个:

DeprecationWarning: integer argument expected, got float

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


当前回答

我有这些:

/home/eddyp/virtualenv/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-x86_64.egg/twisted/persisted/sob.py:12:
DeprecationWarning: the md5 module is deprecated; use hashlib instead import os, md5, sys

/home/eddyp/virtualenv/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-x86_64.egg/twisted/python/filepath.py:12:
DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha

固定它与:

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore",category=DeprecationWarning)
    import md5, sha

yourcode()

现在你仍然得到所有其他DeprecationWarnings,但不是由以下原因引起的:

import md5, sha

其他回答

码头工人的解决方案

在运行python应用程序之前禁用ALL警告 您也可以禁用dockerized测试

ENV PYTHONWARNINGS="ignore::DeprecationWarning"

注释掉下面文件中的警告行:

lib64/python2.7/site-packages/cryptography/__init__.py

来自警告模块的文档:

 #!/usr/bin/env python -W ignore::DeprecationWarning

如果你在Windows上:传递-W ignore::DeprecationWarning作为Python的参数。不过更好的解决方法是强制转换为int类型。

(注意,在Python 3.2中,默认情况下会忽略弃用警告。)

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

- myscrypt。py 2 > / dev /空

我有这些:

/home/eddyp/virtualenv/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-x86_64.egg/twisted/persisted/sob.py:12:
DeprecationWarning: the md5 module is deprecated; use hashlib instead import os, md5, sys

/home/eddyp/virtualenv/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-x86_64.egg/twisted/python/filepath.py:12:
DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha

固定它与:

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore",category=DeprecationWarning)
    import md5, sha

yourcode()

现在你仍然得到所有其他DeprecationWarnings,但不是由以下原因引起的:

import md5, sha