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

后来发现时Python版本太新的原因!Python3以后删除了has_key()方法!

解决办法:

1、重新安装个Python,推荐2.7.6,用的人多些。好多人不习惯用3,仍然在用2

2、修改代码

if not rmap.has_key(cls):

改为

if cls not in rmap:

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

时间: 2024-08-04 13:48:59

AttributeError: 'dict' object has no attribute 'has_key'的相关文章

facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' object has no attribute 'iteritems'

报错原因:在进行facenet进行train_softmax.py训练时,在一轮训练结束进行验证时,报错AttributeError: 'dict' object has no attribute 'iteritems' 解决方案:由于我的python时3.5的,Python3.5中:iteritems变为items,找到train_softmax程序修改如下: facenet pyhton3.5 训练 train_softmax.py 时报错AttributeError: 'dict' obj

'dict' object has no attribute 'a'

a = {} #a.a = 'a' #AttributeError: 'dict' object has no attribute 'a' #a['a'] #KeyError: 'a' a['a'] = 'a' a #{'a': 'a'} 'dict' object has no attribute 'a'

AttributeError: 'str' object has no attribute 'copy'

在使用Python Networkx 中的relabel_nodes函数时,出现: AttributeError: 'str' object has no attribute 'copy' 找了半天也没发现错误出现在哪里,通过比较发现: 如果在定义图的类型时候使用G=nx.MultiDiGraph()就会出现这个错误,改为G=nx.Graph()错误消失. 目测是relabel_nodes函数不支持MultiDiGraph. 附: 1 def relabel_nodes(G, mapping,

AttributeError: 'module' object has no attribute 'dumps'

报错: [[email protected] ~]# ./json.py DATA: [{'a': 'A', 'c': 3.0, 'b': (2, 4)}] Traceback (most recent call last): File "./json.py", line 4, in <module> import json File "/root/json.py", line 8, in <module> data_string = jso

Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attribute 'xxx'".这其实是.pyc文件存在问题. 问题定位: 查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件 问题解决方法: 1. 命名py脚本时,不要与python预留字,模块名等相同 2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件

AttributeError: &#39;dict_values&#39; object has no attribute &#39;translate&#39;

/***************************************************************************************** * AttributeError: 'dict_values' object has no attribute 'translate' * 说明: * 由于目前使用的是Python3,在解读MySQL的ORM库的时候,结果直接遇到这个错误. * * 2016-10-13 深圳 南山平山村 曾剑锋 **********

[Python]attributeError:&#39;module&#39; object has no attribute &#39;dump&#39;

[问题] [代码] 文件名:pickle.py # coding=utf-8 #持久存储 import pickle #b 以二进制的模式打开文件 with open('mydata.pickle','wb') as mysavedata: #用dump保存数据 pickle.dump([1,2,'three'],mysavedata) #b 以二进制的模式打开文件 with open('mydata.pickle','rb') as myreaddata: #使用load恢复数据 list =

python3 AttributeError: &#39;NoneType&#39; object has no attribute &#39;split&#39;

1 from wsgiref.simple_server import make_server 2 3 def RunServer(environ, start_response): 4 start_response('200 ok',[('Content-Type','text/html')]) 5 return '<h1>Hello world</h1>' 6 7 if __name__ == '__main__': 8 httpd = make_server('127.0.0

Faq_flask : AttributeError: ‘module’ object has no attribute ‘autoescape’

原文地址: http://www.suzf.net/thread-0613-153.html 转载须注明原始出处 前些天从 "spider_net" 上找了一篇文章 , 大致就是利用 highcharts + flask + mysql 构建的一个简单的监控系统 ,经过几番挣扎终于还是给捣持出来了 , 现在总结一下 , 分享给大家 .   o_O 部分报错信息: * Detected change in 'flask_web.py', reloading* Restarting wit