pickle模块
Posted xaiobong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pickle模块相关的知识,希望对你有一定的参考价值。
# -*- coding: utf-8 -*- # -- coding: utf-8 -- import pickle class School(): def __init__(self,name): self.name = name def save(self): # 写入 with open(‘my‘, ‘wb‘) as f: pickle.dump(self, f, pickle.HIGHEST_PROTOCOL) """ # 读取 with open(‘my‘, ‘rb‘) as f: data = pickle.load(f) print(data.name) """ print(self.name) s1 = School("北海") s1.save()
以上是关于pickle模块的主要内容,如果未能解决你的问题,请参考以下文章
python常用模块(模块和包的解释,time模块,sys模块,random模块,os模块,json和pickle序列化模块)
python文件操作:pickle模块多次dump后出现的读取问题