11.1. pickle — Python object serialization — Python v2.7.3 documentation

本文深入探讨了Python中pickle模块的使用及其提供的不同序列化协议版本,包括ASCII协议、旧版二进制格式和新版二进制格式的特点与应用。详细解释了如何选择合适的协议版本以优化数据存储效率与可读性,以及在不同Python版本间的兼容性考虑。

11.1. pickle — Python object serialization — Python v2.7.3 documentation

By default, the pickle data format uses a printable ASCII representation.
This is slightly more voluminous than a binary representation. The big
advantage of using printable ASCII (and of some other characteristics of
pickle‘s representation) is that for debugging or recovery purposes it is
possible for a human to read the pickled file with a standard text editor.

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

  • Protocol version 0 is the original ASCII 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.

Refer to PEP 307 for more information.

If a protocol is not specified, protocol 0 is used. If protocol is specified
as a negative value or HIGHEST_PROTOCOL, the highest protocol version
available will be used.

Changed in version 2.3: Introduced the protocol parameter.

A binary format, which is slightly more efficient, can be chosen by specifying a
protocol version >= 1.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值