主要第三方库是pickle
import pickle
# python对象的序列化
class Peoper:
def __init__(self,name,age):
self.name=name
self.age=age
def say(self):
print("你好python")
p = Peoper(name="Jack",age=12)
f = open('p','wb')
pickle._dump(p,f)
f.close()
# 序列化对象的加载
import pickle
f = open('p','rb')
pr=pickle.load(f)
f.close()
print(pr,pr.name,pr.age)
运行结果: