Reputation: 33
Basically what I am trying to do is compare "✔" == "✔"
in Python (2.7). But I keep receiving this error, SyntaxError: Non-ASCII character '\xe2'
. I read the Python docs but the whole Unicode, encoding, and decoding thing is confusing me a lot..
EDIT
I fixed the problem by comparing what should be the ✔ against \u2714
, which is check marks character code (I think that is what you would call it?).
Upvotes: 0
Views: 902
Reputation: 16232
You haven't specified what charset the file uses, so Python defaults to ASCII and fails with a SyntaxError
as soon as it encounters the unicode characters. Adding this at the very beginning of the file should fix that:
# coding:utf-8
More info here: http://www.python.org/dev/peps/pep-0263/
Upvotes: 6
Reputation: 14854
Works at my side:
[avasal@avasal]$ python
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00)
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "✔" == "✔"
True
>>> u"✔" == u"✔"
True
>>>
Upvotes: 0