我正在尝试使用 NetworkX 读取 Shapefile 并使用函数 write_shp()
生成将包含节点和边的 Shapefile,但是当我尝试运行它给出的代码时我出现以下错误:
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。
在此错误之前,它已经给了我另一个说“xrange 不存在”或类似的东西,所以我查了一下,只是将 xrange
更改为 range
在 nx_shp.py 文件中,这似乎解决了它。
根据我的阅读,它可能与 Python 版本(Python2 与 Python3)有关。
最佳答案
在 python3 中,使用 dict.items()
而不是 dict.iteritems()
iteritems()
在python3中被移除了,所以你不能再使用这个方法了。
看看 Python 3.0 Wiki Built-in Changes部分,其中说明:
Removed
dict.iteritems()
,dict.iterkeys()
, anddict.itervalues()
.Instead: use
dict.items()
,dict.keys()
, anddict.values()
respectively.
关于python - 错误 : "' dict' object has no attribute 'iteritems' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30418481/