尝试使用字典填充CSV文件。Dictionary to CSV
这里是我想要的代码:
import csv
my_dict = {'App 1': 'App id1', 'App 2': 'App id2', 'App 3': 'App id3'}
with open('test.csv', 'w') as f:
fieldnames = ['Application Name', 'Application ID']
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(my_dict)
有了这个代码,它只是创造与头一个CSV文件。
我在寻找一个类似的输出:
不错的尝试!保持!有没有需要回答的问题? –
[我如何将Python字典写入csv文件?](https://stackoverflow.com/questions/10373247/how-do-i-write-a-python-dictionary-to-a-csv -file) –
谢谢Alan。 @Moses的回答给了我很多帮助。 – Raj