import cPickle as pickle hashes_file='/tmp/hfile.tmp' #Check the restored Data and return the restored Data def check_data(file_path): fp=open(file_path, 'r') fdata = pickle.load(fp) if(fdata==data_hash): print "The dictionaries are equal" else: print "The dictionaries are not equal" fp.close() return fdata #Check the written file def check_file(file_path): #Create a compare string of pickled data check_pickle_data = pickle.dumps({'Key': None},2) fp=open(file_path, 'r') fdata = fp.read() if(fdata==check_pickle_data): print "The written data is equal" else: print "The written data is NOT equal" print "The file data:" print fdata print "The data is should be:" print check_pickle_data fp.close() #Write a pickel to a file data_hash={'Key': None} fp=open(hashes_file, 'wb') pickle.dump(data_hash, fp, 2) fp.close() #Test the written data hdata=check_data(hashes_file) check_file(hashes_file) print "\n Now write the recieved data again \n" #Store the recieved Data again fp=open(hashes_file,'wb') pickle.dump(hdata, fp, 2) fp.close() #Test the written data hdata=check_data(hashes_file) check_file(hashes_file)