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
2
3pickle.dump( favorite_color, open( "save.p", "wb" ) )
4favorite_color = pickle.load( open( "save.p", "rb" ) )
1pickle_in = open("dict.pickle","rb")
2example_dict = pickle.load(pickle_in)
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