Wednesday, December 9, 2015

Using pickle to se/de-rialize in python.

 # Save a dictionary into a pickle file.
 import pickle
 favorite_color = { "lion": "yellow", "kitty": "red" }
 pickle.dump( favorite_color, open( "save.p", "wb" ) )

 # Load the dictionary back from the pickle file.
 import pickle
 
 favorite_color = pickle.load( open( "save.p", "rb" ) )
 # favorite_color is now { "lion": "yellow", "kitty": "red" }