Sets module deprecated warning

Question:

When I run my python script I get the following warning

DeprecationWarning: the sets module is deprecated

How do I fix this?

Asked By: Dave

||

Answers:

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

Answered By: sykora

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.

Answered By: James Polley

Use the built-in set instead of importing and using sets module.

From documentation:

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

Answered By: Kimvais

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
Answered By: John Machin

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: https://puzzling.org/uncategorized/2009/05/python26-deprecation-warning/)

You can also ignore it programmatically:

import warnings
warnings.simplefilter("ignore", DeprecationWarning)
Answered By: benno
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.