错误“ 'dict'对象没有属性'iteritems'当尝试使用NetworkX的write_shp() [英] Error " 'dict' object has no attribute 'iteritems' " when trying to use NetworkX's write_shp()

查看:279
本文介绍了错误“ 'dict'对象没有属性'iteritems'当尝试使用NetworkX的write_shp()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用NetworkX来读取Shapefile,并使用函数write_shp()来生成包含节点和边的Shapefile(下面这个例子 - https://networkx.github.io/documentation/latest/reference/readwrite.nx_shp.html ),但是当我尝试运行代码它给我以下错误:

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 (following this example - https://networkx.github.io/documentation/latest/reference/readwrite.nx_shp.html), 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安装安装了NetworkX。

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

在此错误之前,它已经给了我另一个说xrange不存在或类似的东西,所以我把它看起来,只是将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.

Ta看看Python Wiki(链接

Take a look at Python Wiki (Link)

内置变更部分,据说


删除dict.iteritems(),dict.iterkeys ()和dict.itervalues()。

Removed dict.iteritems(), dict.iterkeys(), and dict.itervalues().

相反:使用dict.items(),dict.keys()和dict.values()

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

这篇关于错误“ 'dict'对象没有属性'iteritems'当尝试使用NetworkX的write_shp()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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