如何在Python中忽略弃用警告 [英] How to ignore deprecation warnings in Python

查看:398
本文介绍了如何在Python中忽略弃用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直得到这个:

DeprecationWarning: integer argument expected, got float

如何使此消息消失?有没有一种方法可以避免在Python中出现警告?

How do I make this message go away? Is there a way to avoid warnings in Python?

推荐答案

来自 警告模块

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

如果在Windows上:将 -W忽略:: DeprecationWarning 作为Python的参数。最好通过强制转换为 int

If you're on Windows: pass -W ignore::DeprecationWarning as an argument to Python. Better though to resolve the issue, by casting to int.

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

(Note that in Python 3.2, deprecation warnings are ignored by default.)

这篇关于如何在Python中忽略弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆