unicode and socket

Serge Orlov Serge.Orlov at gmail.com
Sat Feb 19 05:51:13 EST 2005


zyqnews at 163.net wrote:
> It's really funny, I cannot send a unicode stream throuth socket with
> python while all the other languages as perl,c and java can do it.

You may really start laughing loudly <wink> after you find out that you
can  send arbitrary python objects over sockets. If you want language
specific way of sending objects, see Irmen's first answer: use pickle.

> then, how about converting the unicode string to a binary stream?

Sure, there are already three answers in this thread that suggest you
to do that. Use encode method of unicode strings.

> It is possible to send a binary through socket with python?

Sure. If it wouldn't be possible to send bytes through sockets with Python
what else do you think could be sent? Perhaps you're confused that
bytes are stored in byte strings in Python, which are often called strings in
documentation and conversations? It will be fixed in Python 3.0, but
these days you have to store bytes in str type.

  Serge.







More information about the Python-list mailing list