如何使用klepto持久化类实例

时间:2019-05-04 14:16:25

标签: python-3.x klepto

我正在尝试用klepto代替搁置来持久化类实例,但是尝试这样做时却发现了漫长的追溯。

我的平台是: python 3.7.3 klepto 0.1.6

示例@ Pickle versus shelve storing large dictionaries in Python ...在上述平台上工作正常。

from   dataclasses import dataclass
@dataclass (frozen=True)
class Target:
    name : str
@dataclass (frozen=True)
class Image:
    target :Target

image_1 = Image (target=Target(name='Crab Nebula'))
image_2 = Image (target=Target(name='Orion Nebula'))
##keys = image_1.name, image_2.name
keys = image_1.target.name, image_2.target.name
values = image_1, image_2
d = dict ( zip (keys,values))
import klepto
a = klepto.archives.dir_archive (dict=d)
a.dump()

a.dump()启动一个冗长的追溯,从...开始。

File "C:\Users\jgv\Documents\Projects\AstroPix_ODB (klepto)\stackoverflow.py", line 20, in <module>
   a.dump()
 File "C:\Users\jgv\AppData\Local\Programs\Python\Python37\lib\site-packages\klepto\_archives.py", line 165, in dump
   self.archive.update(self)

并以...结束

 File "C:\Users\jgv\AppData\Local\Programs\Python\Python37\lib\site-packages\dill\_dill.py", line 1148, in save_dictproxy
   raise ReferenceError("%s does not reference a class __dict__" % obj)
ReferenceError: {} does not reference a class __dict__

0 个答案:

没有答案