title: Using DictWriter to write a subset of a dictionary's keys
body: <p>I wrote a function that serializes a list of dictionaries as a CSV file using the <code>csv</code> module, with code like this:</p>
  
  <pre><code>data = csv.DictWriter(out_f, fieldnames)
  data.writerows(dictrows)
  </code></pre>
  
  <p>However, I sometimes want to write out to a file only a subset of each dictionary's keys. If I pass as <code>fieldnames</code> a subset of the keys that each dictionary has, I get the error:</p>
  
  <pre><code>"dict contains fields not in fieldnames"
  </code></pre>
  
  <p>How can I make it so that DictRows will write just a subset of the fields I specify to CSV, ignoring those fields that are in the dictionary but not in fieldnames?</p>