pickle序列化模块
优势:能够序列化python中所有的类型
缺陷:只能够再python中使用,无法跨语言传输
需求:产生一个对象并保存到文件中,取出来还是一个对象
class C1:
def __init__(self, name, age):
self.name = name
self.age = age
def func1(self):
print('from func1')
def func2(self):
print('from func2')
obj = C1('jason', 18)
import pickle
with open(r'a.txt', 'wb') as f:
pickle.dump(obj, f)
with open(r'a.txt', 'rb') as f:
obj = pickle.load(f)
print(obj.func2())
标签:func2,obj,self,模块,print,序列化,pickle
From: https://www.cnblogs.com/zhanghong1229/p/16874032.html