我尝试使用以下代码导入我的CA-10-60文件:
import csv
with open('CA-10-60.csv', newline='') as f:
reader = csv.DictReader(f, delimiter='')
for row in reader:
print(row['Contract'], row['Serial'])
但是我得到了这个错误:
Traceback (most recent call last):
File "C:/Users/id984876/PycharmProjects/Search Engine SMC/flask/play.py", line 3, in <module>
reader = csv.DictReader(f, delimiter='')
AttributeError: module 'csv' has no attribute 'DictReader'
答案 0 :(得分:0)
你肯定会遇到的一个问题是你的分隔符需要是一个字符串,这可以通过我尝试复制你的错误时发生的事情来证明 -
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\caleb\AppData\Local\Programs\Python\Python36\lib\csv.py", line 87, in __init__
self.reader = reader(f, dialect, *args, **kwds)
TypeError: "delimiter" must be a 1-character string
尝试修复它,看看是否有任何变化。据我所知,csv模块在2.7.14和3.6.3中都有,所以除非你运行的是旧版本,否则我无法想象导入的任何问题。