Pickling and shelving data : shelve « Database « Python






Pickling and shelving data

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

1.Python object persistence for dictionary like objectPython object persistence for dictionary like object
2.Find a word in shelve file