import csvtoCSV = [{'name':'bob','age':25,'weight':200}, {'name':'jim','age':31,'weight':180}]keys = toCSV[0].keys()with open('people.csv', 'w', newline='') as output_file: dict_writer = csv.DictWriter(output_file, keys) dict_writer.writeheader() dict_writer.writerows(toCSV)
编辑:我以前的解决方案不处理订单。正如Wilduck所指出的,此处DictWriter更合适。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)