title: How do I write a Python dictionary to a csv file?
body: <p>I have what I think should be a very easy task that I can't seem to solve.</p>
  
  <p>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.</p>
  
  <p>The closest that I've come is the following (that I got from somebody else's post):</p>
  
  <pre><code>f = open('mycsvfile.csv','wb')
  w = csv.DictWriter(f,my_dict.keys())
  w.writerows(my_dict)
  f.close()
  </code></pre>
  
  <p>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.</p>
  
  <p>Any ideas?</p>