Python如何读写csv数据

Jackey Python 1,026 次浏览 , 没有评论
# 如何读写csv数据
import csv

# 读
rf = open('test.csv', 'r', encoding='gbk')
reader = csv.reader(rf)
print(next(reader))

# for row in reader: print(row)

# 写
wf = open('test_copy.csv', 'w', encoding='gbk')
writer = csv.writer(wf)
for row in reader: writer.writerow(row)

wf.flush()

 

发表回复

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

Go