gpt4 book ai didi

python - 使用 MySQLdb 在 python 中发出警告

转载 作者:行者123 更新时间:2023-11-29 04:31:00 24 4
gpt4 key购买 nike

当我使用 MySQLdb 时收到此消息:

/var/lib/python-support/python2.6/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet

我尝试用

过滤警告
import warnings 
warnings.filterwarnings("ignore", message="the sets module is deprecated from sets import ImmutableSet")

但是,我没有得到更改。
有什么建议吗?
非常感谢。

最佳答案

来自 python documentation : 你可以这样过滤你的警告,这样如果其他警告是由你的代码的其他部分引起的,仍然会显示:

import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
import MySQLdb
[...]

但正如 Alex Martelli 所说,最好的解决方案是更新 MySQLdb,使其不使用已弃用的模块。

关于python - 使用 MySQLdb 在 python 中发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2440799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com