Use Pickle to save and read : Pickle « Database « Python






Use Pickle to save and read

 

import pickle

dFile = open("storage.dat", "wb")

x = 123.467
pickle.dump( x,dFile )
y = 10
pickle.dump( y,dFile )
z = { 1 : "Hello", 2 : "Goodbye" }
pickle.dump( z, dFile )

dFile.close()

iFile = open("storage.dat", "rb" )

d1 = pickle.load(iFile)
print d1
d2 = pickle.load(iFile)
print d2
d3 = pickle.load(iFile)
print d3

iFile.close()
print "Done"

   
  








Related examples in the same category

1.pickling and shelving datapickling and shelving data
2.pickle Module
3.Demonstrates pickling and shelving data
4. unpickle the object