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" ) )
1import pickle
2favorite_color = { "lion": "yellow", "kitty": "red" }
3with open( "save.p", "wb" ) as f:
4 pickle.dump( favorite_color, f)
5with open( "save.p", "rb" ) as f:
6 favorite_color = pickle.load(f)
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)