Python Syntax Non-ASCII character 'xe6' in file (added #-*-coding:utf-8 -*- )
<p>I want to use Python to read the .csv.</p>

<p>At start I search the answer to add the </p>

<pre><code>#!/usr/bin/python
#-*-coding:utf-8 -*-
</code></pre>

<p>so that  can avoid the problem of encoding, but it is still wrong, giving the syntax error:</p>

<blockquote>
  <p>SyntaxError: Non-ASCII character 'xe6' in file csv1.py on line2, but no encoding declared: </p>
</blockquote>

<p>My code:</p>

<pre><code>#!/usr/bin/python
# -*-coding:utf-8 -*-
import csv
with open('wtr1.csv', 'rb') as f:
    for row in csv.reader(f):
        print row
</code></pre>

<p>You've got two different errors here. This answer relates to the <code>with</code> warning. The other error is the ascii encoding error.</p>

<p>You appear to be using a very old version of python (2.5). The <code>with</code> statement is not enabled by default in python 2.5. Instead you have to declare a the top of the file that you wish to use it. Your file should now look like:</p>

<pre><code>#!/usr/bin/python
# -*-coding:utf-8 -*-
from __future__ import with_statement

import csv
with open('wtr1.csv', 'rb') as f:
    for row in csv.reader(f):
        print row
</code></pre>

python