0

我正在尝试用 klepto 代替 shelve 来持久化类实例,但是在尝试这样做时看到了很长的回溯。

我的平台是:python 3.7.3 klepto 0.1.6

@Pickle 与在 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__
4

0 回答 0