python 实现将字典写入csv文件

2023-01-31 05:01:54 文件 写入 字典


shutdown={"yunfeiyang":{"username":"yunfeiyang","binding_house":{0:"1",1:"2"},"reGISter_time":"2018-20"}}

import csv

csvfile = file('csvtest.csv', 'wb')

writer = csv.writer(csvfile)

writer.writerow(['username','binding_hourse','register_time'])

list1=[]

for i in shutdown.values():

 s=tuple(list(i.values()))

 list1.append(s)

writer.writerows(list1)


image.png

相关文章