import pickle
a = {'hello': 'world'}
with open('filename.pickle', 'wb') as handle:
pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL)
with open('filename.pickle', 'rb') as handle:
b = pickle.load(handle)
print a == b
import pickle
# Create a variable
myvar = [{'This': 'is', 'Example': 2}, 'of',
'serialisation', ['using', 'pickle']]
# Open a file and use dump()
with open('file.pkl', 'wb') as file:
# A new file will be created
pickle.dump(myvar, file)