python 实现将字典写入csv文件

发布时间:2019-09-08 09:08:39编辑:auto阅读(2983)


    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

关键字