【发布时间】:2023-01-26 23:38:26
【问题描述】:
我正在尝试打印 csv 文件的每一行,其中包含正在打印的行数。
with open('Polly re-records.csv', 'r',encoding='ISO-8859-1') as file: #file1 path
ct=0
while True:
ct+=1
if file.readline():
print(file.readline(),ct)
else:
break #break when reaching empty line
对于上面的代码,我得到以下输出:
lg1_1,"Now lets play a game. In this game, you need to find the odd one out.",,,,,,,,,,,,,,,,,,,,,,,,
479
sc_2_1,Youve also learned the strong wordsigns and know how to use them as wordsigns. ,,,,,,,,,,,,,,,,,,,,,,,,
480
所以不是从 1 开始的 ct,在我的输出中第一个值直接是 479,除非 if 语句被执行 478 次,否则这是不可能的
我应该做什么更改或阻止打印语句执行的逻辑缺陷是什么
【问题讨论】: