[Tutor] Unicode in List Object

Roman Kreuzhuber rkreuzhuber at hotmail.com
Mon Mar 26 17:05:25 CEST 2007


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"

I then tried:

ListObject = []
ListObject.insert(0,u"Möälasdji".encode('utf-8'))

without success...

So would this error have been raised too if this was an input from a 
GUI-text-object?
I'm sorry for this silly question but I'm more or less completely new to 
python and never encountered similar errors with different languages

roman


>From: Tim Golden <mail at timgolden.me.uk>
>To: Roman Kreuzhuber <rkreuzhuber at hotmail.com>
>CC: tutor at python.org
>Subject: Re: [Tutor] Unicode in List Object
>Date: Mon, 26 Mar 2007 14:38:00 +0100
>
>Roman Kreuzhuber wrote:
>
>>I want to store multiple inputs from text fields in a list-object, which 
>>works as a very small databank. The problem is that this data will contain 
>>unicode characters
>
>I'm not sure why you think this is a problem. A Python list can
>hold anything, including unicode objects or encoded strings. eg,
>
>['White', u'Wei\u00df', 'Wei\xdf']
>
>This is a list containing an entirely ASCII string,
>a unicode object containing a non-ASCII character,
>and the same string encoded as iso-8859-1.
>
>Can you post some code which shows what you're trying
>to do and how it's failing?
>
>TJG

_________________________________________________________________
Sie möchten Teil der Evolution der Kommunikation werden? 
http://www.communicationevolved.com/de-at/



More information about the Tutor mailing list