unicode and socket

Lion Kimbro LionKimbro at gmail.com
Fri Feb 18 17:31:18 EST 2005


You probably want to use UTF-16 or UTF-8 on both sides of the socket.

See http://www.python.org/moin/Unicode for more information.

So, we have a Unicode string...
>>> mystring=u'eggs and ham'
>>> mystring
u'eggs and ham'

Now, we want to send it over:
>>> to_send=mystring.encode('utf-8')
>>> to_send
'eggs and ham'

It's encoded in UTF-8 now.

On the other side, (result=to_send,) we decode:

>>> result=received.decode('utf-8')
>>> result
u'eggs and ham'

You have transfered a unicode string. {:)}=




More information about the Python-list mailing list