Pickling Objects to a File : cPickle « Database « Python Tutorial






import cPickle

flights = {"1":"A", "2":"B","3":"C"}
times = ["230pm", "320pm", "420pm"]

f = open("pickled.dat", "w")

p = cPickle.Pickler(f)

p.dump(flights)
p.dump(times)
f.close()

f = open("pickled.dat", "r")
data = f.read()
print data
f.close()








15.1.cPickle
15.1.1.Pickling Objects to a File
15.1.2.Unpickling Objects from a File
15.1.3.Opening and writing pickled object to a file.