开发者

Python error while using MysqlDb - sets module is deprecated

I'm currently getting the warning every time I run a Python script that uses MySQLdb:

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

I'd rather not mess with their lib if possible. I'm on Ubuntu server. Anyone know an easy way to fix that warning message?

Thanks

UPDATE: Fixed it based on the suggestions below and this link: https://bugzilla.redhat.com/show_bug.cgi?id=505611

import warnings
warnings.filterw开发者_StackOverflow中文版arnings('ignore', '.*the sets module is deprecated.*',
                        DeprecationWarning, 'MySQLdb')
import MySQLdb


Do this before the mysql module is imported

import warnings
warnings.filterwarnings(action="ignore", message='the sets module is deprecated')
import sets


You can ignore the warning using the warnings module, or the -W argument to Python. Don't ignore all DeprecationWarnings, though, just the ones from MySQLdb :)


All it means is the sets module (more specifically the immutableset part) is deprecated, and you should use it's replacement, set. Set is inbuilt so no need to import.

If you need an immutable set, frozenset() should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜