import csv header = ['City', 'AQI', 'PM2.5/1h', 'PM10/1h', 'CO/1h', 'NO2/1h', 'O3/1h', 'O3/8h', 'SO2/1h'] with open('csv_test.csv', 'w', encoding='utf-8', newline='') as f: writer = csv.writer(f) writer.writerow(header)
with 打开的文件,不必使用显示的close来关闭文件,系统自动关闭。