使用MysqlDb时出现Python错误 - 不推荐使用sets模块

Jam*_*mes 6 python mysql

我每次运行使用MySQLdb的Python脚本时都会收到警告:

/var/lib/python-support/python2.6/MySQLdb/__init__.py:34:
DeprecationWarning: the sets module is deprecated
  from sets import ImmutableSet
Run Code Online (Sandbox Code Playgroud)

如果可能的话,我宁可不要乱用他们的lib.我在Ubuntu服务器上.任何人都知道一个简单的方法来修复该警告信息?

谢谢

更新:根据以下建议和此链接修复它:https://bugzilla.redhat.com/show_bug.cgi?id = 505611

import warnings
warnings.filterwarnings('ignore', '.*the sets module is deprecated.*',
                        DeprecationWarning, 'MySQLdb')
import MySQLdb
Run Code Online (Sandbox Code Playgroud)

Joh*_*ooy 6

在导入mysql模块之前执行此操作

import warnings
warnings.filterwarnings(action="ignore", message='the sets module is deprecated')
import sets
Run Code Online (Sandbox Code Playgroud)

  • 请改为忽略来自MySQLdb模块的DeprecationWarnings,或者您可以忽略使用您执行*控制的集合模块或具有匹配文本的其他类型的警告. (2认同)