我怎么知道特定版本的Python支持哪些pickle版本? [英] How do I know which versions of pickle a particular version of Python supports?

查看:614
本文介绍了我怎么知道特定版本的Python支持哪些pickle版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要Python 2.6的脚本.我将在下一个版本中添加一个大型的腌制数据库,并且我想使用最快的腌制版本.如何知道每个版本的Python 2.6和更高版本中可用的酸洗版本?

解决方案

像这样:

>>> import pickle
>>> pickle.compatible_formats
['1.0', '1.1', '1.2', '1.3', '2.0']

修改

我认为依靠最新文档是安全的.例如, Python 3.2.1的修补程序文档声明:

目前有4种不同的协议可用于 腌制.

  • 协议版本0是原始的人类可读协议,并且与Python的早期版本向后兼容.

  • 协议版本1是旧的二进制格式,也与Python的早期版本兼容.

  • 协议版本2是在Python 2.3中引入的.它提供了更高效的新样式类的腌制.

  • 协议版本3已在Python 3.0中添加.它具有对字节的显式支持,并且无法被Python 2.x pickle模块解开.这个
    是当前推荐的协议,请尽可能使用它.

我认为这样很容易确认!

要明确回答您的问题,这意味着Python 2.6-2.7支持Pickle版本< = 2.0,而Python 3.0-3.2支持Pickle版本< = 3.0.

I have a script that requires Python 2.6. I will be adding a large-ish pickled database to the next version, and I want to use the fastest version of pickling. How can I tell which versions of pickling are available in every version of Python 2.6 and later?

解决方案

Like so:

>>> import pickle
>>> pickle.compatible_formats
['1.0', '1.1', '1.2', '1.3', '2.0']

Edit

I think it's safe to rely on the latest documentation. For example the pickle documentation for Python 3.2.1 states:

There are currently 4 different protocols which can be used for pickling.

  • Protocol version 0 is the original human-readable protocol and is backwards compatible with earlier versions of Python.

  • Protocol version 1 is the old binary format which is also compatible with earlier versions of Python.

  • Protocol version 2 was introduced in Python 2.3. It provides much more efficient pickling of new-style classes.

  • Protocol version 3 was added in Python 3.0. It has explicit support for bytes and cannot be unpickled by Python 2.x pickle modules. This
    is the current recommended protocol, use it whenever it is possible.

I think that makes it easy to confirm!

To explicitly answer your question, this means Python 2.6-2.7 support Pickle versions <= 2.0, and Python 3.0-3.2 support Pickle versions <= 3.0.

这篇关于我怎么知道特定版本的Python支持哪些pickle版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆