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
2file_name='my_file.pkl'
3f = open(file_name,'wb')
4pickle.dump(my_data,f)
5f.close()
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)
1with open('mypickle.pickle', 'wb') as f:
2 pickle.dump(some_obj, f)
3
4# note that this will overwrite any existing file
5# in the current working directory called 'mypickle.pickle'
6