Python Dictionary to CSV

后端 未结 6 794
情深已故
情深已故 2020-11-27 16:09

I have written code to read a CSV into a python dictionary, which works fine. I\'m trying to get the dictionary back to a CSV. I have written the following:

         


        
6条回答
  •  庸人自扰
    2020-11-27 16:33

    For posterity:

    You should use iteritems() to iterate over a dictionary, so the last part becomes

    for name, values in itemDict.iteritems():
        print values
        listWriter.writerow(values)
    

提交回复
热议问题