gpt4 book ai didi

python - 我如何知道特定版本的 Python 支持哪些 pickle 版本?

转载 作者:太空狗 更新时间:2023-10-30 00:00:24 31 4
gpt4 key购买 nike

我有一个需要 Python 2.6 的脚本。我将在下一个版本中添加一个大型 pickled 数据库,我想使用最快的 pickle 版本。我如何知道 每个 版本的 Python 2.6 及更高版本中可用的 pickling 版本?

最佳答案

像这样:

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

编辑

我认为依赖最新文档是安全的。例如 pickle documentation for Python 3.2.1状态:

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.

我认为这很容易确认!

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

关于python - 我如何知道特定版本的 Python 支持哪些 pickle 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6687262/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com