示例:
def test():
return 1
import pickle
# import cPickle as pickle #C开发的pickle,速度更快
a = test
b = {'a':'b'}
with open('text.txt','wb') as file:
pickle.dump(a,file)
pickle.dump(b,file)
with open('text.txt','rb') as file2:
#会按顺序重新load出来
c = pickle.load(file2)
d = pickle.load(file2)
print(c())
print(d)
Ref:
https://www.zhihu.com/question/38355589
http://python.jobbole.com/85771/
http://python.jobbole.com/85772/