cpickle支持的python版本_我怎么知道特定版本的Python支持哪些pickle版本?

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值