当我运行我的python脚本时,我收到以下警告
DeprecationWarning: the sets module is deprecated
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
Jam*_*ley 35
停止使用该sets模块,或切换到不被弃用的旧版python.
根据pep-004,sets从v2.6开始被弃用,取而代之的是内置set和frozenset类型.
Joh*_*hin 25
历史:
之前的Python 2.3:没有设定功能
的Python 2.3:sets模块到达
的Python 2.4 set和frozenset内置插件介绍
的Python 2.6:sets模块弃用
您应该更改代码以使用set而不是sets.Set.
如果您仍希望能够支持使用Python 2.3,则可以在脚本开头执行此操作:
try:
set
except NameError:
from sets import Set as set
Run Code Online (Sandbox Code Playgroud)
如果你想修复它,James肯定有正确的答案,但是如果你想关闭弃用警告,你可以像这样运行python:
$ 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
>>>
Run Code Online (Sandbox Code Playgroud)
(来自:http://puzzling.org/logs/thoughts/2009/May/3/python26-deprecation-warning)
您也可以通过编程方式忽略它:
import warnings
warnings.simplefilter("ignore", DeprecationWarning)
Run Code Online (Sandbox Code Playgroud)