how to use unicode?(2)

gfu gfu at public.nn.gx.cn
Mon Jan 27 10:18:07 EST 2003


>gfu wrote:
>> 	>>> u'行都'
>> 	 u'\xcb\xc6\xcd\xf8\xd2\xb3'
>
>In Python 2.2, you cannot put non-ASCII characters into a Unicode 
>literals(*). In Python 2.3, this is possible, but only if you declare 
>the file encoding (i.e. you cannot enter them readily in interactive mode).
>
>So if you want those characters in a string, you need to write
>
>u'\u884c\u90fd'
>
>Here, U+884C and U+90FD are the Unicode code points of the two 
>characters you show above. Alternatively, writing
>
>unicode('行都', 'gb2312')
>
>should also work, provided you have a codec for gb2312 installed (and 
>provided your input is really encoded in gb2312).
>
>HTH,
>Martin
>
>(*) Strictly speaking, you can put any Latin-1 into a Unicode literal if 
>the file is encoded in Latin-1.
>
>-- 
>http://mail.python.org/mailman/listinfo/python-list

= = = = = = = = = = = = = = = = = = = = 
thank you.
In IDLE:	
	>>> s=u'\u884c\u90fd'
    >>> print s
		行都

it's ok.but:
	>>> s = unicode('行都', 'gb2312') 
	UnicodeError: ASCII encoding error: ordinal not in range(128)

how to install a codec for gb2312 ? how to my input is really encoded in gb2312?


gfu







More information about the Python-list mailing list