python csv单行多行写入

import csv

headers = ['class','name','sex','height','year']

rows = [
[1,'xiaoming','male',168,23],
[1,'xiaohong','female',162,22],
[2,'xiaozhang','female',163,21],
[2,'xiaoli','male',158,21]
]

with open('test.csv','w')as f:
f_csv = csv.writer(f)
#单行写入
f_csv.writerow(headers)
#多行写入
f_csv.writerows(rows)

 

posted @ 2020-03-02 20:56  不带R的墨菲特  阅读(1084)  评论(0编辑  收藏  举报