tags:

views:

175

answers:

5

When I run my python script I get the following warning

DeprecationWarning: the sets module is deprecated

How do I fix this?

A: 

You don't need to import the sets module to use them, they're in the builtin namespace.

sykora
+12  A: 

Stop using the sets module, or switch to an older version of python where it's not deprecated.

According to pep-004, sets is deprecated as of v2.6, replaced by the built-in set and frozenset types.

James Polley
+1: fix the warning by fixing the problem that causes the warning. It seems so simple.
S.Lott
A: 

Use the builting set instead of importing sets module

From documentation:

The sets module has been deprecated; it’s better to use the built-in set and frozenset types.

Kimvais
+4  A: 

History:

Before Python 2.3: no set functionality
Python 2.3: sets module arrived
Python 2.4: set and frozenset built-ins introduced
Python 2.6: sets module deprecated

You should change your code to use set instead of sets.Set.

If you still wish to be able to support using Python 2.3, you can do this at the start of your script:

try:
   set
except NameError:
   from sets import Set as set
John Machin
+1  A: 

If you want to fix it James definitely has the right answer, but in case you want to just turn off deprecation warnings, you can run python like so:

$ python -Wignore::DeprecationWarning 
Python 2.6.2 (r262:71600, Sep 20 2009, 20:47:22) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sets
>>> 

(From: http://puzzling.org/logs/thoughts/2009/May/3/python26-deprecation-warning)

You can also ignore it programmatically:

import warnings
warnings.simplefilter("ignore", DeprecationWarning)
benno