python中csv文件写入

import csv
birth_header = [1,2,4,5,6,7]
#这个作为标题传入文件
birth_data = [['123','12','黑救护车你是'],['sav','savc','afcv']]
#这是数据

with open('./a.csv','a+',newline='') as f:
#打开文件并以a(追加)的方式写入
    # with open(birth_weight_file, "w") as f:
    writer = csv.writer(f)
    writer.writerows([birth_header])
    writer.writerows(birth_data)
    f.close()

你可能感兴趣的:(python基础知识)