Socket and array

Sam free.condiments at gmail.com
Wed Feb 7 12:28:10 EST 2007


On 07/02/07, JStoneGT at aol.com <JStoneGT at aol.com> wrote:
> How to send an array via socket to the other end?Thanks.

What you want is a serialisation solution - turning objects into a
string format, and vice versa. Python provides a system for this in
its standard library, in the pickle module. Some pseudocode might look
like:

#sender
import pickle
socket_send(pickle.dumps(my_list))

#receiver
import pickle
my_list = pickle.loads(read_all_socket_data())

However, this should only be used if you trust where the data is
coming from; with untrusted data, a more restrictive format (such as
JSON, perhaps, or a similar lightweight notation system if you are
only sending lists) would be a good idea.

--Sam



More information about the Python-list mailing list