小编典典

Python 3.2在csv.DictReader中跳过一行

python

使用DictReader时,如何跳过CSV中的一行记录?

码:

import csv
reader = csv.DictReader(open('test2.csv'))
# Skip first line
reader.next()
for row in reader:
    print(row)

错误:

Traceback (most recent call last):
  File "learn.py", line 3, in <module>
    reader.next()
AttributeError: 'DictReader' object has no attribute 'next'

阅读 233

收藏
2021-01-20

共1个答案

小编典典

next(reader)改为使用。

来源:csv.DictReader文档

2021-01-20