views:

68

answers:

1

I'm trying to create hebrew strings but get syntax errors. It works in the IDLE shell but not in Pydev. Here's what I've tried so far:

s = 'מחרוזת בעברית' #works in the shell only
s = u'מחרוזת בעברית' #doesn't work at all
s = unicode("מחרוזת בעברית", "UTF-8") #also doesn't work at all

I get a syntax error: Non-UTF-8 code starting with '\xee'. What does it mean and what shall I do to create hebrew strings?

+4  A: 

Does your source file start with a # -*- coding: utf-8 -*- line? Is your file actually encoded as utf-8 (and not some other encoding)?

It's supposed to work (the first line, other lines are not valid Python 3).

Virgil Dupras
Thanks. adding this comment to the source file worked. But I still have questions:1. I thought the interpreter ignores all comments. Are there any other comment formats which aren't ignored?2. The thing worked for me even after I deleted this comment. I mean, once I put the comment, it worked even after removing the comment. Can you explain that?
snakile
I had thought of it after I answered, but IIRC, Python3's default source code encoding became UTF-8 with Python 3 (under Python 2, it was ascii), so this comment is now useless. Yes, all comment *but* this one are ignored, it's a special case (the only one I think).So for Python 3, the only possible problem was then the encoding of your file itself.
Virgil Dupras