出错代码
with open('web_data.csv', 'rb') as csvfile:
reader = csv.DictReader(csvfile)
column = [row for row in reader]
print(column)
报错:_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
因为此csv文件并非二进制文件, 只是一个文本文件。进行如下修改后可以解决。
改进代码
with open("web_data.csv", "rt", encoding="utf-8") as csvfile:
reader = csv.DictReader(csvfile)
column = [row for row in reader]
print(column)