title: Trouble reading in Unicode strings from CSV file to DictReader in Python
body: <p>I have a CSV file I'm trying to read in using DictReader.</p>
  
  <p>But doing just this:</p>
  
  <pre><code>with("BeerRatings.csv", "r", "utf-8") as f:
      reader = csv.DictReader(f)
      for line in reader:
          print line
  </code></pre>
  
  <p>gives me some ugly unicode as such:</p>
  
  <pre><code>{'Rating': '4', 'Brewery': 'Tr\xc3\xb6egs Brewing Company', 'Beer name': 'Tr\xc3\xb6egs Hopback Amber Ale'}
  {'Rating': '4.59', 'Brewery': 'Brasserie Dieu Du Ciel', 'Beer name': 'P\xc3\xa9ch\xc3\xa9 Mortel - Bourbon Barrel Aged'} etc.
  </code></pre>
  
  <p>So, reading on stackoverflow, I editted my code to this, using the codecs module:</p>
  
  <pre><code>import codecs
  
  with codecs.open("BeerRatings.csv", "r", "utf-8") as f:
      reader = csv.DictReader(f)
      for line in reader:
          print line
  </code></pre>
  
  <p>But this is giving me a <code>UnicodeEncodeError: 'ascii' codec can't encode character u'\xea' in position 9: ordinal not in range(128)</code>. </p>
  
  <p>Any tips on how to go fix this? </p>
  
  <p>UPDATE aka more flailing around:</p>
  
  <pre><code>def UnicodeDictReader(utf8_data, **kwargs):
      csv_reader = csv.DictReader(utf8_data, **kwargs)
      for row in csv_reader:
          yield {key: unicode(value, 'utf-8') for key, value in row.iteritems()}
  
  with open("BeerRatings.csv", "r") as f:
      reader = UnicodeDictReader(f)
      for line in reader:
          print line
  </code></pre>
  
  <p>THis still gives me a less than ideal output...</p>
  
  <pre><code>{'Rating': u'4', 'Brewery': u'Tr\xf6egs Brewing Company', 'Beer name': u'Tr\xf6egs Hopback Amber Ale'}
  {'Rating': u'4.59', 'Brewery': u'Brasserie Dieu Du Ciel', 'Beer name': u'P\xe9ch\xe9 Mortel - Bourbon Barrel Aged'}
  </code></pre>