def readtable(file, array):
f = open(file)
f.readline()
for i in f:
for j in i:
array[i].append(j)
readtable("DADSA RESIT CWK JULY 2018.csv", database)
我尝试用Python将CSV文件扫描到数组中,但每次执行此代码时,我都会收到以下消息:
"TypeError: list indices must be integers or slices, not str".
有什么办法解决这个问题吗?
如果它有帮助,如果我删除倒数第二行并以"array.append(i)
“结束,则数组扫描正常,但它将每一行都打印为一行。我也希望能够将它们分解成列。
发布于 2018-07-12 02:15:25
使用标准库中的csv.reader
。
import csv
with open("DADSA RESIT CWK JULY 2018.csv", newline='') as f:
r = csv.reader(f)
l = list(r)
https://stackoverflow.com/questions/51291873
复制相似问题