本文介绍了莳萝与Python的pickle模块有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Python3代码中有一个大对象,当尝试用pickle模块腌制时,会引发以下错误:

I have a large object in my Python3 code which, when tried to be pickled with the pickle module throws the following error:

TypeError: cannot serialize '_io.BufferedReader' object

但是,dill.dump()dill.load()能够无缝保存和恢复对象.

However, dill.dump() and dill.load() are able to save and restore the object seamlessly.

  1. 是什么原因导致pickle模块出现问题?
  2. 现在dill保存并重建对象没有任何错误,是否有任何方法可以验证用dill进行的酸洗和酸洗是否顺利?
  3. pickle失败但dill成功的可能性如何?
  1. What causes the trouble for the pickle module?
  2. Now that dill saves and reconstructs the object without any error, is there any way to verify if the pickling and unpickling with dill went well?
  3. How's it possible that pickle fails, but dill succeeds?

推荐答案

我是dill的作者.

1)最简单的方法是查看此文件: https ://github.com/uqfoundation/dill/blob/master/dill/_objects.py ,其中列出了pickle可以序列化的内容,以及dill可以序列化的内容.

1) Easiest thing to do is look at this file: https://github.com/uqfoundation/dill/blob/master/dill/_objects.py, it lists what pickle can serialize, and what dill can serialize.

2)您可以尝试dill.copydill.checkdill.pickles来检查不同级别的酸洗和解酸. dill还包括用于检测和诊断dill.detectdill.pointers中的序列化问题的实用程序.

2) you can try dill.copy and dill.check and dill.pickles to check different levels of pickling and unpickling. dill also more includes utilities for detecting and diagnosing serialization issues in dill.detect and dill.pointers.

3)dill建立在pickle的基础上,并通过注册新的序列化函数对其进行了扩充.

3) dill is built on pickle, and augments it by registering new serialization functions.

4)dill包括序列化变体,使用户可以从不同的对象依赖项序列化策略中进行选择(在dill.settings中)-包括源代码提取和使用dill.source进行对象重构(以及stdlib 模块).

4) dill includes serialization variants which enable the user to choose from different object dependency serialization strategies (in dill.settings) -- including source code extraction and object reconstitution with dill.source (and extension of the stdlib inspect module).

这篇关于莳萝与Python的pickle模块有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 19:31