Uri
Uri

Reputation: 26966

Hebrew characters in Python code on eclipse

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

Answers (4)

LiorK
LiorK

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

jambox
jambox

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

McDowell
McDowell

Reputation: 108899

Ensure that the encoding the editor is using to enter data matches the declared encoding in the file metadata.

Eclipse file properties dialog

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

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

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

Related Questions