Skip to content

Commit 2c22923

Browse files
author
Mofan Zhou
committed
create basic34
1 parent c24aa52 commit 2c22923

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

basic/34_pickle.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# View more python learning tutorial on my Youtube and Youku channel!!!
2+
3+
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
4+
# Youku video tutorial: http://i.youku.com/pythontutorial
5+
6+
import pickle
7+
8+
a_dict = {'da': 111, 2: [23,1,4], '23': {1:2,'d':'sad'}}
9+
10+
# pickle a variable to a file
11+
file = open('pickle_example.pickle', 'wb')
12+
pickle.dump(a_dict, file)
13+
file.close()
14+
15+
# reload a file to a variable
16+
with open('pickle_example.pickle', 'rb') as file:
17+
a_dict1 =pickle.load(file)
18+
19+
print(a_dict1)
20+
21+
22+
23+
24+
25+
26+

0 commit comments

Comments
 (0)