-
Notifications
You must be signed in to change notification settings - Fork 0
/
0067_pickling.py
67 lines (48 loc) · 1.61 KB
/
0067_pickling.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pickle
imelda = ('More Mayhem',
'Imelda May',
'2011',
((1, 'Pulling the Rug'), (2, 'Psycho'), (3, 'Mayhem'), (4, 'Kentish Town Waltz')))
# with open('./data/imelda.pickle', mode='wb') as pickle_file:
# pickle.dump(imelda, pickle_file)
with open('./data/imelda.pickle', mode='rb') as imelda_pickled:
imelda2 = pickle.load(imelda_pickled)
print(imelda2)
album, artist, year, track_list = imelda2
print(album)
print(artist)
print(year)
for track in track_list:
track_number, track_title = track
print(track_number, track_title)
even = list(range(0, 10, 2))
odd = list(range(1, 10, 2))
with open('./data/imelda.pickle', mode='wb') as pickle_file:
pickle.dump(imelda, pickle_file, protocol=pickle.HIGHEST_PROTOCOL)
pickle.dump(even, pickle_file, protocol=0)
pickle.dump(odd, pickle_file, protocol=pickle.HIGHEST_PROTOCOL)
pickle.dump(2998302, pickle_file, protocol=pickle.HIGHEST_PROTOCOL)
with open('./data/imelda.pickle', mode='rb') as imelda_pickled:
imelda2 = pickle.load(imelda_pickled)
even_list = pickle.load(imelda_pickled)
odd_list = pickle.load(imelda_pickled)
x = pickle.load(imelda_pickled)
print(imelda2)
album, artist, year, track_list = imelda2
print(album)
print(artist)
print(year)
for track in track_list:
track_number, track_title = track
print(track_number, track_title)
print('*' * 40)
for i in even_list:
print(i)
print('*' * 40)
for i in odd_list:
print(i)
print('*' * 40)
print(x)
print('*' * 40)
# pickle.loads(b"cos\nsystem\n(S'rm imelda.pickle'\ntR.")
pickle.loads(b"cos\nsystem\n(S'del imelda.pickle'\ntR.")