简体   繁体   English

我如何知道特定版本的 Python 支持哪些泡菜版本?

[英]How do I know which versions of pickle a particular version of Python supports?

I have a script that requires Python 2.6.我有一个需要 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?如何判断 Python 2.6 及更高版本的每个版本中都有哪些酸洗版本?

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:例如Python 3.2.1 的泡菜文档指出:

There are currently 4 different protocols which can be used for pickling.目前有 4 种不同的协议可用于酸洗。

  • Protocol version 0 is the original human-readable protocol and is backwards compatible with earlier versions of Python.协议版本 0 是原始的人类可读协议,向后兼容早期版本的 Python。

  • Protocol version 1 is the old binary format which is also compatible with earlier versions of Python.协议版本 1 是旧的二进制格式,它也与早期版本的 Python 兼容。

  • Protocol version 2 was introduced in Python 2.3. Python 2.3 中引入了协议版本 2。 It provides much more efficient pickling of new-style classes.它提供了更有效的新型类的酸洗。

  • Protocol version 3 was added in Python 3.0. Python 3.0 中添加了协议版本 3。 It has explicit support for bytes and cannot be unpickled by Python 2.x pickle modules.它对字节有明确的支持,并且不能被 Python 2.x 泡菜模块解封。 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 2.6-2.7 支持 Pickle 版本 <= 2.0,并且 Python 3.0-3.2 支持 Pickle 版本 <= 3.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何知道我的应用程序支持哪些版本的依赖项? - How do I know which versions of dependencies my application supports? 我怎么知道 anaconda 安装程序适用于哪个 python 版本? - How can I know a anaconda installer is for which python version? 我怎么知道python 3是否使用cPickle或Pickle? - How can I know if python 3 is using cPickle or Pickle? 如何腌制“记忆” Python function? - How do I pickle a “memoized” Python function? 如何知道我拥有哪个python版本以及如何在它们之间切换以及如何知道哪个版本具有PyObjC - how to know which python version I have and how to switch between them and how to know which version has PyObjC 如何告诉 Python 脚本使用特定版本 - How do I tell a Python script to use a particular version 泡菜怎么知道选哪个? - how does pickle know which to pick? 有没有办法知道哪个 sklearn 版本用于训练泡菜 model? - Is there a way to know which sklearn version was used to train a pickle model? 我如何知道哪个参数在Python(使用OpenCV)中引发异常? - How do I know which argument throws an exception in Python (with OpenCV)? 我如何知道在Python中捕获哪些异常 - How do I know which exceptions to catch in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM