错误:""dict"对象没有属性"iteritems" [英] Error: " 'dict' object has no attribute 'iteritems' "

查看:84
本文介绍了错误:""dict"对象没有属性"iteritems"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用NetworkX读取Shapefile并使用函数write_shp()生成将包含节点和边的Shapefile,但是当我尝试运行代码时,出现以下错误:

I'm trying to use NetworkX to read a Shapefile and use the function write_shp() to generate the Shapefiles that will contain the nodes and edges, but when I try to run the code it gives me the following error:

Traceback (most recent call last):   File
"C:/Users/Felipe/PycharmProjects/untitled/asdf.py", line 4, in
<module>
    nx.write_shp(redVial, "shapefiles")   File "C:\Python34\lib\site-packages\networkx\readwrite\nx_shp.py", line
192, in write_shp
    for key, data in e[2].iteritems(): AttributeError: 'dict' object has no attribute 'iteritems'

我正在使用Python 3.4,并通过pip install安装了NetworkX.

I'm using Python 3.4 and installed NetworkX via pip install.

在发生此错误之前,它已经给了我另一个错误,它说"xrange不存在"或类似的内容,因此我进行了查找,只是在nx_shp.py文件中将xrange更改为range,这似乎解决它.

Before this error it had already given me another one that said "xrange does not exist" or something like that, so I looked it up and just changed xrange to range in the nx_shp.py file, which seemed to solve it.

据我了解,它可能与Python版本(Python2与Python3)有关.

From what I've read it could be related to the Python version (Python2 vs Python3).

推荐答案

就像在python3中一样,使用dict.items()代替dict.iteritems()

As you are in python3 , use dict.items() instead of dict.iteritems()

iteritems()已在python3中删除,因此您无法再使用此方法.

iteritems() was removed in python3, so you can't use this method anymore.

看看Python 3.0 Wiki 内置更改部分,其中指出:

Take a look at Python 3.0 Wiki Built-in Changes section, where it is stated:

已删除dict.iteritems()dict.iterkeys()dict.itervalues().

相反:使用dict.items()dict.keys()dict.values() 分别.

Instead: use dict.items(), dict.keys(), and dict.values() respectively.

这篇关于错误:""dict"对象没有属性"iteritems"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆