SyntaxError: Non-ASCII character

Steven D'Aprano steve at pearwood.info
Sun Jul 17 07:01:17 EDT 2016


On Sun, 17 Jul 2016 07:57 pm, Rustom Mody wrote:

> I dare say that Python3’s :
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/ariston/foo.py", line 31
>     wf = wave.open(“test.wav”, “rb”)
>                        ^
> SyntaxError: invalid character in identifier

If the caret ^ would line up with the invalid character, that would give a
hint to the reader which character was invalid. Or perhaps showing, or
naming, the invalid character in the error message:

SyntaxError: invalid character '“' in identifier


> is probably worse than Python2’s
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "foo.py", line 31
> SyntaxError: Non-ASCII character '\xe2' in file foo.py on line 31, but no
> encoding declared; see http://python.org/dev/peps/pep-0263/ for details

I'm not sure. I think the Python 2 version is less useful: it doesn't show
you the line, you have to go look for it yourself. Then you have to work
out what character is \xe2, which is generally not easy because your editor
is unlikely to show the escape code but rather some apparently normal
looking character.



-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list