[英]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.