【发布时间】:2020-10-25 13:21:52
【问题描述】:
def read_file():
with open("bla.csv", "r") as Blabla:
reader = csv.reader(BlaBla)
for column in reader:
one = column[1]
two = column[2]
three = column[3]
four = column[4]
bla_line.append([one, two, three, four])
count, c = 50, 1
while c < count:
read_file()
c = c + 1
如何在循环时逐行读取文件?每个c 一行。
c = 0 = read line 0
c = 1 = read line 1
c = 2 = read line 2
等等等等……
islice、pandas 等等,到目前为止还没有为我解决。
我需要这个结构,因为它是用于此处未列出的另一个功能和后续操作。
到目前为止,append 操作运行良好。这里的问题是像我描述的那样遍历文件。
【问题讨论】:
-
这能回答你的问题吗? Reading rows from a CSV file in Python