티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Error: " 'dict' object has no attribute 'iteritems' "
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:
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'
I'm using Python 3.4 and installed NetworkX via pip install.
저는 파이썬 3.4를 사용하고 있으며 pip 설치를 통해 NetworkX를 설치했습니다.
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.
이 오류가 발생하기 전에 이미 "xrange는 존재하지 않는다" 또는 비슷한 내용의 다른 오류를 제공했기 때문에, 저는 그것을 찾아 nx_shp.py 파일에서 xrange를 range로 변경했고, 이것은 해결된 것처럼 보였습니다.
From what I've read it could be related to the Python version (Python2 vs Python3).
제가 읽은 바로는 파이썬 버전과 관련이 있을 수 있습니다(Python2 vs Python3).
높은 점수를 받은 Solution
As you are in python3 , use dict.items()
instead of dict.iteritems()
python3에서 dict.iteritems() 대신 dict.items()를 사용하세요.
iteritems()
was removed in python3, so you can't use this method anymore.
python3에서 iteritems가 제거되었기 때문에 더 이상 이 방법을 사용할 수 없습니다.
Take a look at Python 3.0 Wiki Built-in Changes section, where it is stated:
Python 3.0 Wiki 기본 제공 변경사항 섹션을 살펴보십시오.
Removed
dict.iteritems()
,dict.iterkeys()
, anddict.itervalues()
.Instead: use
dict.items()
,dict.keys()
, anddict.values()
respectively.
dict.iteritems(), dict.iterkeys() 및 dict.itervalues()를 제거했습니다.
대신: 각각 dict.items(), dict.keys() 및 dict.values()를 사용하십시오.
가장 최근 달린 Solution
In Python2, dictionary.iteritems()
is more efficient than dictionary.items()
so in Python3, the functionality of dictionary.iteritems()
has been migrated to dictionary.items()
and iteritems()
is removed. So you are getting this error.
Python2에서는 dictionary.iteritems()가 dictionary.items()보다 더 효율적이므로 Python3에서는 dictionary.iteritems()의 기능이 dictionary.items()로 마이그레이션되었고 iteritems()가 제거되었습니다. 따라서 이 오류가 발생합니다.
Use dict.items()
in Python3 which is same as dict.iteritems()
of Python2.
Python2의 dict.iteritems()와 동일한 Python3에서 dict.items()를 사용합니다.
출처 : https://stackoverflow.com/questions/30418481/error-dict-object-has-no-attribute-iteritems
'개발 > 파이썬' 카테고리의 다른 글
문자열 리스트에서 빈 문자열 제거하기 (0) | 2022.12.31 |
---|---|
pytest를 사용하여 오류 발생여부 확인하기 (0) | 2022.12.31 |
Python에서 모든 하위 디렉터리 가져오기 (0) | 2022.12.31 |
파일의 마지막 n줄 가져오기 (0) | 2022.12.30 |
웹 스크래핑의 HTTP 403 에러 수정하기 (0) | 2022.12.29 |