socket send help

Chris Rebert clp at rebertia.com
Fri Dec 26 01:17:40 EST 2008


On Thu, Dec 25, 2008 at 10:08 PM, greywine at gmail.com <greywine at gmail.com> wrote:
> Hi again,
>
> I've done some more playing around with socket and socketserver and
> have discovered I can send strings or lists with socket.send() by
> converting to bytes.  But lists with strings in them or dicts can't be
> converted by bytes().  How can I send those?

If you're sending structured data rather than just bytestrings, you
should use proper serialization. Use the `json`, `pickle`, or
`marshal` modules to convert your data to an external representation
in bytes, send the bytes thru the socket, then deserialize the bytes
back into data structures using the same module again.
The Python std lib docs are your friend.

Merry Christmas,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list