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