You really should use module pickle for that ...
# use module pickle to save/dump and load a dictionary object
# or just about any other intact object
import pickle
# create the test dictionary
before_d = {}
before_d[1]="Name 1"
before_d[2]="Name 2"
before_d[3]="Name 3"
# pickle dump the dictionary
fout = open("dict1.dat", "w")
pickle.dump(before_d, fout)
fout.close()
# pickle load the dictionary
fin = open("dict1.dat", "r")
after_d = pickle.load(fin)
fin.close()
print before_d # {1: 'Name 1', 2: 'Name 2', 3: 'Name 3'}
print after_d # {1: 'Name 1', 2: 'Name 2', 3: 'Name 3'}
Last edited by vegaseat; Nov 19th, 2008 at 11:32 am.
May 'the Google' be with you!