📜  python 写入 csv 文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:11.932000             🧑  作者: Mango

代码示例2
import csv  

header = ['name', 'area', 'country_code2', 'country_code3']
data = ['Afghanistan', 652090, 'AF', 'AFG']

with open('countries.csv', 'w', encoding='UTF8') as f:
    writer = csv.writer(f)

    # write the header
    writer.writerow(header)

    # write the data
    writer.writerow(data)