0 votes
in Other by
Error: “ 'dict' object has no attribute 'iteritems' ”

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'

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

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.

1 Answer

0 votes
by
To get rid of this Error: “ 'dict' object has no attribute 'iteritems' ” if you are using python3, you can use the dict.items()function instead of dict.iteritems().

The dict.iteritems() is removed in python3, so this function can't be used anymore.

But if you are a user of Python 2 then you can use  dict.iteritems() to get rid of this error.

Related questions

0 votes
asked Aug 13, 2020 in XML by SakshiSharma
+1 vote
asked Jan 15, 2021 in Cassandra by SakshiSharma
...