The pickle
module allows you to serialize objects to a string, so you can transfer it via the disk or a socket.
You could also use multiprocessing
, which is intended for parallelism, but could be used here too. (Actually, multiprocessing
relies on pickle
.)