import pickle
d=dict(url='index.html',title='首页',content='内容')
byte_data=pickle.dumps(d)
print(byte_data)
with open(r'abc.pkl','wb') as filer:
pickle.dump(d,filer)
filer.close()
with open(r'abc.pkl','rb') as f:
aa=pickle.load(f)
print(aa)
print(type(aa))
import pickle
class Person:
def __init__(self,name):
self.name=name
def show(self):
print(self.name)
a=Person('123')
# 序列化对象
with open(r'abc.pkl','wb') as f:
pickle.dump(a,f)
f.close()
# 反序列化
with open(r'abc.pkl','rb') as f:
aa=pickle.load(f)
print(aa.show())