我正在开发一个使用 Pickle 来实现存档游戏的游戏项目(我知道这样做的缺点——我们不在这里讨论)。这非常有效:不幸的是,标准 Pickle 无法处理我希望在未来版本中做的一些事情,所以我改用 Dill。不幸的是,它不起作用:它_pickle.UnpicklingError: pickle exhausted before end of frame
在加载保存时给出。
重申一下:这段代码和我正在使用的测试用例与 Pickle 完美配合。只有莳萝有问题。
我正在像这样导入莳萝:
try:
import dill as pickle
except ImportError:
print("Failed to load Dill serialization library: some features may not work correctly.")
import pickle
完整的回溯是这样的:
Traceback (most recent call last):
File "C:/Users/Schilcote/workspace/pyweek19/main.py", line 605, in game_init
gamestate=pickle.load(open(os.path.join(_savedir,"save.sav"),"rb"))
File "C:\Python34\lib\site-packages\dill\dill.py", line 199, in load
obj = pik.load()
File "C:\Python34\Lib\pickle.py", line 1036, in load
dispatch[key[0]](self)
File "C:\Python34\Lib\pickle.py", line 1321, in load_global
module = self.readline()[:-1].decode("utf-8")
File "C:\Python34\Lib\pickle.py", line 247, in readline
"pickle exhausted before end of frame")
_pickle.UnpicklingError: pickle exhausted before end of frame
我什至不知道如何开始诊断。这是怎么回事?
编辑:
为了澄清,错误来自反序列化。