unicode converting

Leif K-Brooks eurleif at ecritters.biz
Tue Mar 15 22:56:42 EST 2005


Maxim Kasimov wrote:
> Diez B. Roggisch wrote:
> 
>> Maxim Kasimov wrote:
>>
>>
>>> there are a few questions i can find answer in manual:
>>> 1. how to define which is internal encoding of python unicode strings
>>> (UTF-8, UTF-16 ...) 
>>
>> It shouldn't be your concern - but you can specify it using " ./configure
>> --enable-unicode=ucs2" or --enable-unicode=ucs4. You can't set it to 
>> utf-8
>> or utf-16.
> 
> is that means that python internal unicode format is ucs2 or ucs4?
> i'm concerning with the qustion because i need to send data to external
> application in ucs2 encoding

The internal format Python stores Unicode strings in is an 
implementation detail; it has nothing to do with how you send data. To 
do that, you encode your string into a suitable encoding:

 >>> s = u"Some Unicode text."
 >>> s
u'Some Unicode text.'
 >>> s.encode('utf-16')
'\xff\xfeS\x00o\x00m\x00e\x00 \x00U\x00n\x00i\x00c\x00o\x00d\x00e\x00 
\x00t\x00e\x00x\x00t\x00.\x00'



More information about the Python-list mailing list