tags:

views:

415

answers:

3

hi all, I'm currently getting the warning:

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

everytime I run a python script that uses mysqldb. 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.filterwarnings('ignore', '.*the sets module is deprecated.*', DeprecationWarning, 'MySQLdb')
import MySQLdb
A: 

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.

Dominic Bou-Samra
Unfortunately it isn't his code that's using the sets module.
Thomas Wouters
hi Dominic.. thanks for the reply. Its the mysqldb library so I don't want to go changing their codebase unless I have to. any ideas?
A: 

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 :)

Thomas Wouters
thanks Thomas, how would I ignore the ones just from mysqldb?
You pass the right module as the `module` argument to the warnings filter.
Thomas Wouters
A: 

Do this before the mysql module is imported

import warnings
warnings.filterwarnings(action="ignore", message='the sets module is deprecated')
import sets
gnibbler
Please ignore DeprecationWarnings from the MySQLdb module instead, or you might ignore uses of the sets module you *do* control, or other types of warnings that have matching text.
Thomas Wouters