I have what I think should be a very easy task that I can’t seem to solve.
How do I write a Python dictionary to a csv file? All I want is to write the dictionary keys to the top row of the file and the key values to the second line.
The closest that I’ve come is the following (that I got from somebody else’s post):
f = open('mycsvfile.csv','wb') w = csv.DictWriter(f,my_dict.keys()) w.writerows(my_dict) f.close()
The problem is, the above code seems to only be writing the keys to the first line and that’s it. I’m not getting the values written to the second line.