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()
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
1Python 3.4.1 (default, May 21 2014, 12:39:51)
2[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
3Type "help", "copyright", "credits" or "license" for more information.
4>>> mylist = ['I wish to complain about this parrot what I purchased not half an hour ago from this very boutique.', "Oh yes, the, uh, the Norwegian Blue...What's,uh...What's wrong with it?", "I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it!", "No, no, 'e's uh,...he's resting."]
5>>>
6>>> import pickle
7>>>
8>>> with open('parrot.pkl', 'wb') as f:
9... pickle.dump(mylist, f)
10...
11>>> with open('parrot.pkl', 'wb') as f:
12... new_list = pickle.load(mylist, f)
13
14
1Python 3.4.1 (default, May 21 2014, 12:39:51)
2[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
3Type "help", "copyright", "credits" or "license" for more information.
4>>> import pickle
5>>> with open('parrot.pkl', 'rb') as f:
6... mynewlist = pickle.load(f)
7...
8>>> mynewlist
9['I wish to complain about this parrot what I purchased not half an hour ago from this very boutique.', "Oh yes, the, uh, the Norwegian Blue...What's,uh...What's wrong with it?", "I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it!", "No, no, 'e's uh,...he's resting."]
10>>>
11