Python 读写 CSV 文件

## typical usage

注意dictwriter需要提供fieldnames
“`
with open(‘csvfile’, ‘wt’, newline=”) as f:
writer = csv.DictWriter(f, fieldnames=[], extrasaction=’ignore’)
writer.writeheader()
writer.writerow(d) # list of dict if writerows

with open(‘csvfile’, ‘wt’, newline=”) as f:
writer = csv.writer(f)
writer.writerow(l) # list of list if writerows

with open(‘csvfile’, ‘rt’) as f:
reader = csv.reader(f)
for row in reader:
print(row)
“`

About 逸飞

后端工程师

发表评论

电子邮件地址不会被公开。 必填项已用*标注