How to fix encoding issue when writing to csv file
<p>i have some encoding issuse when writing to csv file</p>

<p>how can i fix it</p>

<pre><code>import csv


a = [s.encode('utf-8') for s in a]
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>Traceback (most recent call last):
  File "test.py", line 6, in &lt;module&gt;
    a = [s.encode('ascii') for s in a]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1: ordinal not in range(128)
</code></pre>

<p>How to make program work and write it to csv file?</p>

<p>I ran your code and it works without throwing any errors. Only thing is that your csv file contains byte encoded values. Values with a b' at the front. Is this what you were trying to accomplish? I am using python 3.5.2 .</p>

<p>In the event you do not want byte encoded data just remove the </p>

<pre><code>a = [s.encode('utf-8') for s in a]
</code></pre>

<p>And it should work. Here is the output of your data into the csv when I ran it on my machine. </p>

<p><a href="http://puu.sh/r8ksr/d778437622.png" rel="nofollow">http://puu.sh/r8ksr/d778437622.png</a></p>

python csv encoding