reader.next() # advances to second line
for row in reader: # loops over remaining lines
while i < 10: # loops over i
print row # prints current row - this would be the second row in the first forloop iteration... 10 times, because you loop over i.
i=i+1 # increments i, so the next rows, i is already >=10, your while-loop only affects the second line.
为什么一开始就有那个while循环?
您可以轻松地执行以下操作:
reader = csv.reader(f)
for rownum, row in enumerate(reader):
if rownum: #skip first line
print row
你的代码正在做你让它做的事情。。。 (而且,你的标题也有误导性:读者只阅读了一次,你只是打印了10次)
为什么一开始就有那个while循环? 您可以轻松地执行以下操作:
相关问题 更多 >
编程相关推荐