您的位置:首页 > 移动开发 > Objective-C

AttributeError: 'dict' object has no attribute 'has_key'

2017-11-01 18:34 1516 查看
AttributeError: ‘dict’ object has no attribute ‘has_key’

Python 3 已弃用
has_key
这一方法

错误代码:

ssCnt = {}
if not ssCnt.has_key(can): ssCnt[can]=1
else: ssCnt[can] += 1


修正后:

ssCnt = {}
if can not in ssCnt: ssCnt[can]=1
else: ssCnt[can] += 1


参考:

What’s New In Python 3.0

‘dict’ object has no attribute ‘has_key’
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: