1import pickle
2with open('Fruits.obj', 'wb') as fp:
3 pickle.dump(banana, fp)
4
1import pickle
2# load : get the data from file
3data = pickle.load(open(file_path, "rb"))
4# loads : get the data from var
5data = pickle.load(var)
1import pickle
2# dump : put the data of the object in a file
3pickle.dump(obj, open(file_path, "wb"))
4# dumps : return the object in bytes
5data = pickle.dump(obj)
1 1 # Save a dictionary into a pickle file.
2 2 import pickle
3 3
4 4 favorite_color = { "lion": "yellow", "kitty": "red" }
5 5
6 6 pickle.dump( favorite_color, open( "save.p", "wb" ) )
7
1 1 # Load the dictionary back from the pickle file.
2 2 import pickle
3 3
4 4 favorite_color = pickle.load( open( "save.p", "rb" ) )
5 5 # favorite_color is now { "lion": "yellow", "kitty": "red" }
6