1import pickle
2
3a = {'hello': 'world'}
4
5with open('filename.pickle', 'wb') as handle:
6 pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL)
7
8with open('filename.pickle', 'rb') as handle:
9 b = pickle.load(handle)
10
11print a == b
12
1import pickle #credits to stack overflow user= blender
2
3a = {'hello': 'world'}
4
5with open('filename.pkl', 'wb') as handle:
6 pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL)
7
8with open('filename.pkl', 'rb') as handle:
9 b = pickle.load(handle)
10
11print (a == b)
1import pickle
2file_name='my_file.pkl'
3f = open(file_name,'wb')
4pickle.dump(my_data,f)
5f.close()
1import pickle
2
3pickle.dump( favorite_color, open( "save.p", "wb" ) )
4favorite_color = pickle.load( open( "save.p", "rb" ) )
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