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)

python csv单行多行写入

 

上一篇:mysql 数据类型 枚举类型与集合类型


下一篇:MySQL-删除数据(DELECT)