inserting Unicode character in dictionary - Python

Joe Strout joe at strout.net
Fri Oct 17 19:32:36 CEST 2008


On Oct 17, 2008, at 11:24 AM, Marc 'BlackJack' Rintsch wrote:

>> kw = 'генских'
>>
> What do you mean by "does not work"?  And you are aware that the above
> snipped doesn't involve any unicode characters!?  You have a byte  
> string
> there -- type `str` not `unicode`.

Just checking my understanding here -- are the following all true:

1. If you had prefixed that literal with a "u", then you'd have Unicode.

2. Exactly what Unicode you get would be dependent on Python properly  
interpreting the bytes in the source file -- which you can make it do  
by adding something like "-*- coding: utf-8 -*-" in a comment at the  
top of the file.

3. Without the "u" prefix, you'll have some 8-bit string, whose  
interpretation is... er... here's where I get a bit fuzzy.  What if  
your source file is set to utf-8?  Do you then have a proper UTF-8  
string, but the problem is that none of the standard Python library  
methods know how to properly interpret UTF-8?

4. In Python 3.0, this silliness goes away, because all strings are  
Unicode by default.

Thanks for any answers/corrections,
- Joe









More information about the Python-list mailing list