Python equivalent of java ObjectOutputStream and ObjectInputStream?

In java, I can transfer objects between server and client using an object output stream and an object input stream . Is there something equivalent in python?

Connected:

+3
source share
2 answers

Python's brine module provides object serialization and deserialization functionality. http://docs.python.org/library/pickle.html

This is not particularly secure, so you should always check the incoming data, but it should support your needs.

+9
source

Pipe(), . http://docs.python.org/library/multiprocessing.html#multiprocessing.Pipe

( )

import multiprocessing

class ObjectToSend:
    def __init__(self,data):
        self.data = data

obj = ObjectToSend(['some data'])

#create 2 read/write ends to a pipe
a, b = multiprocessing.Pipe()
#serialize and send obj across the pipe using send method
a.send(obj) 
#deserialize object at other end of the pipe using recv method
print(b.recv().data)
+3

All Articles