3
我的CSV文件爲什麼csv.DictReader給我一個沒有屬性的錯誤?
200
Service
我把到解釋的代碼是
snav = csv.DictReader(open("screennavigation.csv"), delimiter=',')
print snav.fieldnames
['200']
for line in snav:
... print(line)
...
{'200': 'Service'}
snav["200"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: DictReader instance has no attribute '__getitem__'
我認爲DictReader
是爲了返回一個字典。我懷疑我錯過了一些殘酷的事情。