赞
踩
csv.reader会返回一个reader对象,这是一个可迭代的对象,从csv文件读取的每一行都作为字符串列表返回。
输出csv文件的前100行:
with open('test.csv', 'r', newline='', encoding='utf-8-sig', errors='ignore') as f:
csv_write = csv.reader(f)
for i, row in enumerate(csv_write):
if i == 100:
break
else:
print(row) # 输出前100行
输出特定的行:
with open('test.csv', 'r', newline='', encoding='utf-8-sig', errors='ignore') as f:
csv_write = csv.reader(f)
for i, row in enumerate(csv_write):
if i == 100:
print(row) # 输出第100行
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。