python pickle模块:python变量及对象的序列化
1、pickle.dump
将python变量保存为二进制文件
2、pickle.load
从二进制文件中读到python变量
3、pickle.dumps
将python对象序列化保存为变量
4、pickle.loads
对python变量反序列化为python对象
# -*- coding:utf-8 -*-
import pickle
class Bar(object):
def __init__(self):
self.close=5000
self.open=6000
self.high=4000
self.low=4000
self.datetime='2018-08-09 07:00:00'
def show(self):
print(self.__dict__)
bar=Bar()
bar.show()
f=open('pickle.pkl','wb')
pickle.dump(bar,f)
f=open('pickle.pkl','rb')
g=pickle.load(f)
print(g)
网友评论