Serialization example
# pickle_save.py
# program to create and save some data
import pickle
mystring = 'this is just a simple string'
mylist = ['this is my list', 5, 'bla bla']
file = open('mydata.pickled', 'w')
pickle.dump(mystring, file)
pickle.dump(mylist, file)
# pickle_read.py
# program to read in the pickled data
import pickle
file = open('mydata.pickled', 'r')
mydata = pickle.load(file)
print mydata
mydata = pickle.load(file)
print mydata
Output:
this is just a simple string
['this is my list', 5, 'bla bla']
© 2001 Per Kraulis
$Date: 2001/05/09 11:03:35 $