python 对象序列化 pickling_python对象序列化之pickle

本片文章主要是对pickle官网的阅读记录。

The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy. Pickling (and unpickling) is alternatively known as “serialization”, “marshalling,” [1] or “flattening”; however, to avoid confusion, the terms used here are “pickling” and “unpickling”.

pickle是python标准模块之一,不需要再额外安装。

pickle用来 序列化和反序列化 Python object structure。其实就是一种数据存储方式,将python的数据结构以特定的形式保存下来。另外,经过pickle序列化后的数据不是human-readable的。

这里提一下老外对事物的命名习惯,pickle是腌制的意思,那么对python object的"腌制",其实就是一种数据处理,至于数据处理的规则是什么,这里暂时不做进一步介绍。

“Pickling”  就是将有层次结构的python object转换成字节流;“unpickling”就是相反的过程。

说明: 如果碰到“Pickling” “serialization”, “marshalling,”  or “flattening”,都是表达相同的意思,翻译成"序列化"就好了;如果单词前加了un,就翻成“反序列化”。

Warning:The pickle module is not secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.

不要去序列化 错误的或者恶意的 结构化数据,也不要去反序列化 不受信任或未授权的数据源。意思就是“序列化”和“反序列化”要按照pickle模块的规则来进行。

Data stream format

The data format used by pickle is Python-specific. This has the advantage that there are no restrictions imposed by external standards such as JSON or XDR (which can’t represent pointer sharing); however it means that non-Python programs may not be able to reconstruct pickled Python objects.

pickle使用的数据格式是Python语言特有的。非Python程序可能不能重构 被序列化 的数据。

By default, the pickle data format uses a relatively compact binary representation. If you need optimal size characteristics, you can ef

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值