gpt4 book ai didi

python csv阅读器,从第二行开始循环

转载 作者:太空狗 更新时间:2023-10-29 19:36:49 26 4
gpt4 key购买 nike

在 python 2.7.3 中,如何从第二行开始循环?例如

first_row = cvsreader.next();
for row in ???: #expect to begin the loop from second row
blah...blah...

最佳答案

first_row = next(csvreader)  # Compatible with Python 3.x (also 2.7)
for row in csvreader: # begins with second row
# ...

测试它是否真的有效:

>>> import csv
>>> csvreader = csv.reader(['first,second', '2,a', '3,b'])
>>> header = next(csvreader)
>>> for line in csvreader:
print line
['2', 'a']
['3', 'b']

关于python csv阅读器,从第二行开始循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16350480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com