Encoding issues in python how to fix it
<p>I get this error while writing data to csv file</p>

<pre><code>import csv
a = [u'eaTfxfwz', u'Edward', u'O\u2019Connell', u'ejoconnell@sbcglobal.net', u'Santa Clara', u'CA', 'UNITED STATES', u'150 Saratoga Avenue #306', u'', u'Santa Clara, CA', u'95051', u'', u'408-835-2209', u'None', u'', '', u'2012-010', u'pjOjJfwT', u'Undefined', u'Import', u'     ', ' San Jose HQ, CA ', '', '', u'Undefined', '', u'None', '', '', u'Undefined', u'Not Considered', '', u'']
f3 = open('test.csv', 'at')
writer = csv.writer(f3,delimiter = ',', lineterminator='\n',quoting=csv.QUOTE_ALL)
writer.writerow(a)
</code></pre>

<p>error</p>

<pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 1: ordinal not in range(128)
</code></pre>

<p>How to fix it</p>

<p>You can use <code>utf-8</code> encoding.</p>

<pre><code>import csv
aenc=[]
a = [u'eaTfxfwz', u'Edward', u'O\u2019Connell', u'ejoconnell@sbcglobal.net', u'Santa Clara', u'CA', 'UNITED STATES', u'150 Saratoga Avenue #306', u'', u'Santa Clara, CA', u'95051', u'', u'408-835-2209', u'None', u'', '', u'2012-010', u'pjOjJfwT', u'Undefined', u'Import', u'     ', ' San Jose HQ, CA ', '', '', u'Undefined', '', u'None', '', '', u'Undefined', u'Not Considered', '', u'']
for x in a:
    aenc.append(x.encode('utf-8'))
with open('test.csv', 'wb') as f3:
    writer = csv.writer(f3,delimiter = ',', lineterminator='\n', quoting=csv.QUOTE_ALL)
    writer.writerow(aenc)
</code></pre>

python encoding utf