Python如何读写csv数据

Jackey Python 860 次浏览 , 没有评论
# 如何读写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