1、读取excel数据,输出为list,使用csv_reader
使用官网上的实例
import csv
with open('world_alcohol.csv','rb') as f:
reader = csv.reader(f)
for line in reader:
print(line)
得到的结果:
Error: iterator should return strings, not bytes (did you open the file in text mode?)
最后发现应该这样:
import csv
with open('world_alcohol.csv') as f:
world_alcohol = list(csv.reader(f))
print(world_alcohol)
不能加'rb'?不太理解,是为记。
网友评论