[Tutor] Unicode in List Object
Kent Johnson
kent37 at tds.net
Mon Mar 26 17:33:57 CEST 2007
Roman Kreuzhuber wrote:
> Thanks for the quick response!
> I see! Oh I didn't realize that it's not the list which raises an error.
> For a test I tried to insert a string containing a unicode character as
> follows:
>
> ListObject = []
> ListObject.insert(0,u"Möälasdji")
>
> which raises: "SyntaxError: Non-ASCII character '\xfc' in file C:\python
> proj\lists\main.py on line 48, but no encoding declared; see
> http://www.python.org/peps/pep-0263.html for details"
Did you look at the link? It's not the easiest reading for a newbie, I
admit.
Python expects your source file to contain ASCII text unless you tell it
otherwise. You can tell it what encoding to use with a special comment
at the top of the file. Try adding
# coding=utf-8
(or whatever the appropriate coding is) to the top of your source file.
> So would this error have been raised too if this was an input from a
> GUI-text-object?
No, this is a syntax error in your source file.
Kent
More information about the Tutor
mailing list