早上好,
我想创建一个继承自列表的类,例如我可以做的:
import pickle
object_list = []
object_list.append(an_object)
object_list.append(an_other_object)
object_list.dump('/home/user/my_file')
或
import pickle
[an_objet, an_other_object].dump('/home/user/my_file')
我不知道如何创建我的课程,
感谢您阅读
答案 0 :(得分:0)
我明白了
import pickle
class my_list(list):
def__init___(self, *args)
list.__init__(self, *args)
def dumps(self, path):
with open(path, 'wb') as f:
pick = pickle.Pickler(f)
pick.dump(self)
def load(self, path):
with open(path, 'rb') as f:
pick = pickle.Unpickler(f)
for i in pick.load():
self.append(i)