title: python how to trim trailing spaces in csv DictReader keys
body: <p>I am using python (2.6) csv DictReader. My input file has a header line where the column names have trailing spaces:</p>
  
  <pre><code>colname1,      colname2     ,col3, etc.
  XX, YY, ZZ
  </code></pre>
  
  <p>The returned dict object has key() = <code>['colname1', 'colname2     ', 'col3']</code></p>
  
  <p>Is there an option to trim leading and trailing spaces from the keys?</p>
  
  <p>--edit</p>
  
  <p>The problem arises in processing by key names:</p>
  
  <pre><code>with open(fname) as f:
     r = csv.DictReader(f)
     for row in r:
        print "processing", r["column1"], r["column2"]
  </code></pre>
  
  <p>The files are database dumps. And the dump program is way too smart - it adjust the output column width depending on data -- which means different sets of selects are going to have different column width and different key lengths. Sometimes I must use <code>r['column2    ']</code> and sometimes pad or reduce spaces. ouch!</p>