-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpickle_test.py
46 lines (30 loc) · 980 Bytes
/
pickle_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# encoding: utf-8
"""
pickle_test.py
Created by Sam Cook on 2011-04-23.
Copyright (c) 2011 __MyCompanyName__. All rights reserved.
"""
import sys
import os
from pickle import *
def main():
to_store = [1, 2, 3, 5, 6, 21, 9]
dict_to_store = {'this': 99, 'that': "chicken", 'the_other':to_store}
bigger = [dict_to_store, ['how', 'are', 'you']]
with open("out.pickle", "w") as out_file:
pickle_f = Pickler(out_file)
pickle_f.dump(bigger)
with open("out.pickle", "r") as in_file:
pickle_i = Unpickler(in_file)
inbound = pickle_i.load()
print inbound
inbound.append("hello")
with open("out.pickle", "w") as out_file:
pickle_f = Pickler(out_file)
pickle_f.dump(inbound)
with open("out.pickle", "r") as in_file:
pickle_i = Unpickler(in_file)
print pickle_i.load()
if __name__ == '__main__':
main()