使用MysqlDb时Python错误 - sets模块已被弃用
我现在在运行一个使用MySQLdb的Python脚本时,每次都会收到警告:
/var/lib/python-support/python2.6/MySQLdb/__init__.py:34:
DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
如果可以的话,我不想去修改他们的库。我是在Ubuntu服务器上。有没有简单的方法可以解决这个警告信息?
谢谢
更新:根据下面的建议和这个链接修复了问题: https://bugzilla.redhat.com/show_bug.cgi?id=505611
import warnings
warnings.filterwarnings('ignore', '.*the sets module is deprecated.*',
DeprecationWarning, 'MySQLdb')
import MySQLdb
3 个回答
0
这段话的意思是,集合模块中的一个部分(更具体来说是不可变集合的那部分)已经不再推荐使用了,你应该用它的替代品,叫做集合(set)。集合是内置的,所以你不需要额外导入。
如果你需要一个不可变的集合,可以使用frozenset(),这个应该可以满足你的需求。
1
你可以使用warnings
模块来忽略这个警告,或者在运行Python时加上-W
这个参数。不过,不要忽略所有的DeprecationWarnings
(弃用警告),只忽略来自MySQLdb
的那些就可以了 :)
6
在导入mysql模块之前,请先做这个
import warnings
warnings.filterwarnings(action="ignore", message='the sets module is deprecated')
import sets