错误:"'dict' 对象没有属性 'iteritems' " [英] Error: " 'dict' object has no attribute '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:Python34libsite-packages
etworkx
eadwrite
x_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不存在"或类似的东西,所以我查了一下,只是将xrange
更改为range
在 nx_shp.py 文件中,这似乎解决了它.
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屋!