Python小白丁笔记(17)----- 另一种文件格式——CSV

    xiaoxiao2022-07-02  110

    filepath = input('请输入文件名称:') city_list = pocess_json_file(filepath) city_list.sort(key=lambda city: city['aqi']) # 列名 lines = [] lines.append(list(city_list[0].keys())) for city in city_list: lines.append(list(city.values())) f = open('aqi.csv', 'w', encoding='utf-8', newline='') writer = csv.writer(f) for line in lines: writer.writerow(line) f.close()

    最新回复(0)