我试图pickle类实例,引用http://stefaanlippens.net/python-pickling-and-dealing-with-attributeerror-module-object-has-no-attribute-thing.html 但是给了我
在try.py在
import pickle
class abc(object):
def __init__(self):
self.a = 10
def save(self):
pickle.dump(self,open("try.pkl","wb"))
if __name__ == '__main__':
a = abc()
abc.__module__ = "try"
a.save()
pickle.PicklingError: Can't pickle <class 'try.abc'>: it's not the same object as try.abc
我是不是犯了个错误? 是否有不同的解决方案来为独立目的pickle对象
如果你把你的
abc.__module__ = "try"
拿走,一切都很好。在我在末尾添加了一些代码来重新加载数据并打印出来,以显示它是成功的。在
相关问题 更多 >
编程相关推荐