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()