import pickle class A: users = {} c = 1 def get_self(self): return self def n(self): return 1 def pick_str_to_obj(self): return 'xiaoming' a = A()
---------------------------------------------- dumpss = pickle.dumps(a)
reversess = pickle.loads(dumpss)
----------------------------------------------
with open('aaad.txt', 'wb') as f: picklestring = pickle.dump(a, f) with open('aaad.txt', 'rb') as f: obj = pickle.load(f) print(obj.n())
ps:多个对象咋办??
list, dict也是对象哟