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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM