今晚像往常一样打开Aptana写Python程序时,一个has_key调用报错了,代码如下:
代码如下 | 复制代码 |
info = {} 控制台: Traceback (most recent call last): |
说是字典对象没有has_key这个属性?一开始我以为是电脑神经了,多运行几次,还是报这个错误。看来电脑是没问题,在仔细读程序,一点问题都没有啊!后来想到会不会因为info没有成员才会报错?这不可能,但我还是往info里加了成员:
代码如下 | 复制代码 |
info = {"key":"key"} print(info.has_key("key")) ) |
结果还是一样提示字典对象没有has_key这个属性,于是我拿到命令行下运行,居然跑通了?
代码如下 | 复制代码 |
D:Python27>python.exe D:workspaceaptanatestmain.py True |
正严重郁闷中,难道Aptana中的PyDev出毛病了?但其他的语句比如if..else..while...def...class..import等都没有问题,为何偏偏就不能用has_key?最后我决定把Python的版本打印看看:
代码如下 | 复制代码 |
import sys |
控制台:
代码如下 | 复制代码 |
3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AMD64)] |
Python3版本,到cmd下打印Python版本:
代码如下 | 复制代码 |
D:Python27>python.exe -V |
Python2版本,难道说Python3版本移除了has_key这个我最经常用的函数?到官网一查,发现如下这段话:
Removed: apply(). Instead of apply(f, args) use f(*args).
Removed callable(). Instead of callable(f) you can use isinstance(f, collections.Callable). The operator.isCallable() function is also gone.
Removed coerce(). This function no longer serves a purpose now that classic classes are gone.
Removed execfile(). Instead of execfile(fn) use exec(open(fn).read()).
Removed the file type. Use open(). There are now several different kinds of streams that open can return in the io module.
Removed reduce(). Use functools.reduce() if you really need it; however, 99 percent of the time an explicit for loop is more readable.
Removed reload(). Use imp.reload().
Removed. dict.has_key() – use the in operator instead.
这真是中招了,还好没有浪费太多时间,没有把编辑器、系统重装,最后查看项目创建时使用的解释器果真是Python3版本:
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔