AttributeError: 'dict' object has no attribute 'interitems'
来源:互联网 发布:网络舞蹈培训学校 编辑:程序博客网 时间:2024/05/18 02:08
看《机器学习实战》时,运行2-1的程序,报错AttributeError: 'dict' object has no attribute 'interitems',查了一下百度说是因为python2和python3存在兼容性问题要把iteritems改成items就ok了。
问题语句:
sortedClassCount = sorted(classCount.iteritems(),key=operator.itemgetter(1),reverse=True)
改成
sortedClassCount = sorted(classCount.items(),key=operator.itemgetter(1),reverse=True)
就解决了,问题是这本书说使用Python2编写代码,所以我也是用的Python2写的不知道怎么就错了非得写成Python3格式就好了
阅读全文
0 0
- AttributeError: 'dict' object has no attribute 'interitems'
- AttributeError: 'dict' object has no attribute 'iteritems'
- AttributeError: 'dict' object has no attribute 'iteritems'
- AttributeError: 'dict' object has no attribute 'has_key'
- AttributeError: 'dict' object has no attribute 'iteritems'
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- Python3下机器学习实战KNN代码出现AttributeError: ‘dict’ object has no attribute错误
- AttributeError: 'classmethod' object has no attribute '__module__'
- AttributeError: 'module' object has no attribute 'getpass'
- AttributeError: ‘NoneType’ object has no attribute ‘clone’
- AttributeError: 'module' object has no attribute 'Serial'
- AttributeError: 'NoneType' object has no attribute 'clone'
- AttributeError: 'tuple' object has no attribute 'Multi'
- AttributeError: 'Response' object has no attribute 'json'
- AttributeError: 'module' object has no attribute(转)
- AttributeError: 'Connection' object has no attribute 'connection_errors'
- AttributeError: 'module' object has no attribute 'randint'
- 自动内存管理机制(2)——虚拟机对象的创建、内存布局和访问定位
- 美团云OVS-DPDK 2017年工作总结(SRIOV、热升级、热扩容、跨OVS-kernel热迁移)
- Reinforcement learning tips
- pdf_分页器脚本程序
- Construct 2做游戏
- AttributeError: 'dict' object has no attribute 'interitems'
- 1036. 跟奥巴马一起编程(15)
- Linux学习之C语言编程训练2
- OpenCV-Python-Tutorial[3]
- python中read() readline()以及readlines()用法
- test
- 数据库的增删改查
- zoj--3983(CCPC秦皇岛)
- 51Nod-1264-线段相交