Non-ASCII character '\xe2' in file but no encoding declared

血红的双手。 提交于 2019-12-11 17:16:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/54388973/non-ascii-character-xe2-in-file-but-no-encoding-declared

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!