[Solved] Non-ASCII character ‘xe2’ in file but no encoding declared
I wrote a script to extract signals from the MIT-BIH dataset using the wfdb python library. The script was working fine when I was running it on windows but I recently shifted to Mac. After installing all the dependencies I got an error when I tried to import processing from the wfdb library. This is the error I get:
SyntaxError: Non-ASCII character ‘xe2’ in file /usr/local/lib/python2.7/site-packages/scipy/stats/_continuous_distns.
py on line 3346, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
import wfdb works fine but there seems to be a problem when I do from wfdb import processing
. Is there any way to solve this issue?
This error is caused due to copying and pasting code from web which causes stray byte floating. You can find it by running.
with open('my_script.py', 'r') as ms:
for i, line in enumerate(ms):
if 'xe2' in line:
print(i, repr(line))
And the line and its index value will be printed where there is ‘xe2’:
4, "xe2 word=string.printable(random.randint[0,61]) # Gets the random word"
Note: You should replace my_script.py with your respective .py file.
Please add following line at the top of the code.
# -*- coding: utf-8 -*-
Also, avoid using non-ascii quotations.