title: How to sanitize CSV input with one-space strings?
body: <p>So here's the situation:</p>
  
  <ul>
  <li><p>I'm reading CSV files where the majority of the time, empty cells are just empty strings. Some files that come in the same set, for whatever reason, have one-space strings in 'empty cells' instead of empty strings.</p></li>
  <li><p>I'm using <code>csv</code>'s DictReader to read from these files (with ',' as the delimiter) and it will automatically convert empty strings to <code>None</code> type values prior to my inserting them into a PostgreSQL db. </p></li>
  <li><p>I tried registering a Dialect object that set <code>skipinitialspace=True</code>, but now they remain empty strings which, unlike <code>None</code>, is still an invalid input for SQL table columns that I have set to integer values (so I'm guessing DictReader converts empty strings to <code>None</code> prior to removing the leading whitespace).</p></li>
  </ul>
  
  <p>How can I get around this?</p>
  
  <p>Disclaimer: I could reach a solution by just converting all the one-space-strings to <code>None</code> types myself after I have read the values and have the row's dict from DictReader, but it seems clunky and I'd prefer a more elegant solution if possible.</p>
  
  <p><strong>Example normal csv</strong></p>
  
  <pre><code>foo_id,foo_text,foo_value
  1,'hello',4
  3,,2
  </code></pre>
  
  <p><strong>Example problem csv</strong></p>
  
  <pre><code>bar_id,bar_text,bar_value
  1,'hello',4
  3, ,2
  </code></pre>
  
  <p><strong>Example csv read script</strong></p>
  
  <pre><code>with open('foo.txt') as csv_file:
      csv.register_dialect('example_dialect', delimiter=',', skipinitialspace=True)
      gtfsreader = DictReader(csv_file, dialect='example_dialect')
      for row in gtfsreader:
          print(row)
  </code></pre>