title: Writing a dictionary to a CSV file via DictWriter (Python)
body: <p>DictWriter just doesn't seem to be working for me.</p>
  
  <p>Current code:</p>
  
  <pre><code>myfile = open('hashdict.csv', 'wb')
  fieldnames = ('md5', 'value')
  myWriter = csv.DictWriter(myfile, fieldnames=fieldnames)
  headers = dict((n,n) for n in fieldnames)
  myWriter.writerow(headers)
  for n in dictToSearch:
      myWriter.writerow(n)
  myfile.close()
  </code></pre>
  
  <p>Traceback: </p>
  
  <pre><code>Traceback (most recent call last):
    File "hash.py", line 42, in &lt;module&gt;
      myWriter.writerow(n)
    File "C:\Python27\lib\csv.py", line 148, in writerow
      return self.writer.writerow(self._dict_to_list(rowdict))
    File "C:\Python27\lib\csv.py", line 144, in _dict_to_list
      ", ".join(wrong_fields))
  ValueError: dict contains fields not in fieldnames: d, 1, a, 5, 0, d, 0, a, 1, 7
  , 0, e, 5, e, a, 9, f, e, b, 6, f, 7, 9, 6, 1, 3, 6, 3, f, 6, d, 9
  </code></pre>
  
  <p>The alphanumerical characters are from an MD5 hash, but that's about all I can tell you. I've looked at the documentation and can't seem to make sense of it. What I'm trying to do is make a CSV file out of the dictionary called dictToSearch. </p>
  
  <p>Thanks in advance for any help, and let me know if you need any other information.</p>
  
  <p>Link to full code: <a href="http://pastebin.com/A3E4AJfV" rel="nofollow">http://pastebin.com/A3E4AJfV</a></p>