优势:能够序列化python中的所有类型
缺点:只能在python中使用,无法跨语言传输,并且局限性很大
pickle模块的应用
使用pickle模块序列化反序列化只能以二进制模式 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: res = pickle.load(f) print(res) # <__main__.C1 object at 0x000001E55C246A30> res.func1() # from func1 print(res.name) # jason """ 产生一个对象并保存到文件中,取出后仍然是一个对象, 并且序列化前后的类的空间也不能发生变化 """
标签:func1,res,self,模块,print,序列化,pickle From: https://www.cnblogs.com/juzijunjun/p/16873889.html