Pickling and shelving data
import cPickle, shelve
print "Pickling lists."
variety = ["sweet", "hot", "dill"]
shape = ["whole", "spear", "chip"]
brand = ["Claussen", "Heinz", "Vlassic"]
f = open("pickles1.dat", "w")
cPickle.dump(variety, f)
cPickle.dump(shape, f)
cPickle.dump(brand, f)
f.close()
print "\nUnpickling lists."
f = open("pickles1.dat", "r")
variety = cPickle.load(f)
shape = cPickle.load(f)
brand = cPickle.load(f)
print variety, "\n", shape, "\n", brand
f.close()
Related examples in the same category