Reputation: 26966
I'm writing python code on eclipse and whenver I use hebrew characters I get the following syntax error:
SyntaxError: Non-ASCII character '\xfa' in file ... on line 66, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
How do I declare unicode/utf-8 encoding?
I tried adding
-*- coding: Unicode -*-
or
-*- coding: utf-8 -*-
in the commented section in the beginnning of the py file. It didn't work.
I'm running eclipse with pydev, python 2.6 on windows 7.
Upvotes: 3
Views: 3481
Reputation: 1680
I tried it also and here is my conclusion: You should add
# -*- coding: utf-8 -*-
at the very first line in your file. And yes, I work with windows...
If I got it right, you are missing the #
Upvotes: 3
Reputation: 580
I had the same thing and it was because I'd tried to do:
a='言語版の記事'
When I should have done:
a=u'言語版の記事'
I think it's python/pydev complaining when trying to parse the source, rather than eclipse as such.
Upvotes: 0
Reputation: 108899
Ensure that the encoding the editor is using to enter data matches the declared encoding in the file metadata.
This isn't something unique to Eclipse or Python; it applies to all character data formats and text editors.
Python has a number of options for dealing with string literals in both the str
and unicode
types via escape sequences. I believe there were changes to string literals between Python 2 and 3.
Upvotes: 2
Reputation: 798716
"Unicode" is certainly wrong, and \xfa
is not UTF-8. Figure out which encoding is actually being used and declare that instead.
Upvotes: 0