[Tutor] Unicode in List Object
Tim Golden
mail at timgolden.me.uk
Mon Mar 26 17:45:18 CEST 2007
Andre Engels wrote:
> 2007/3/26, Roman Kreuzhuber <rkreuzhuber at hotmail.com>:
>>
>> 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"
>
>
> At the top of your Python file, below the line which might be there that
> reads
>
> #!/usr/bin/python
>
> but above any other line, add:
>
> # -*- coding: utf-8 -*-
>
> This tells the parser that this file should be read as unicode.
Ummm... just to be picky: it tells the parser that the file
was saved (by whatever text editor you use) using the utf-8
encoding and should be converted to unicode on that basis.
Obviously if you use some other encoding, such as iso-8859-1,
it needs to read:
# -*- coding: iso-8859-1 -*-
Roman: there are several Unicode tutorials available for
Python. One recently highlighted was:
http://boodebr.org/main/python/all-about-python-and-unicode
and there are several listed here:
http://wiki.python.org/moin/Unicode
TJG
More information about the Tutor
mailing list