python pickle的用法实例代码

import pickle

a1 = ‘apple’
b1 = {1: ‘One’, 2: ‘Two’, 3: ‘Three’}
c1 = [‘fee’, ‘fie’, ‘foe’, ‘fum’]
f1 = open(‘temp.pkl’, ‘wb’)
pickle.dump(a1, f1, True)
pickle.dump(b1, f1, True)
pickle.dump(c1, f1, True)
f1.close()
f2 = open(‘temp.pkl’, ‘rb’)
a2 = pickle.load(f2)
print(a2)
b2 = pickle.load(f2)
print(b2)
c2 = pickle.load(f2)
print(c2)

你可能感兴趣的:(工具类)