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?
Answers:
You don’t need to import the sets
module to use them, they’re in the builtin namespace.
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.
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.
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
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)
When I run my python script I get the following warning
DeprecationWarning: the sets module is deprecated
How do I fix this?
You don’t need to import the sets
module to use them, they’re in the builtin namespace.
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.
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.
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
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)