Python - 模块 pickle

pickle

  1. pickle 模块可以用来(解)序列化 python 对象
  2. pickle 功能可以将程序运行中的对象保存为文件。如果加载保存过的 pickle 文件,可以立刻复原之前程序运行中的对象。
  3. 官方文档地址
  4. pickle.dump(obj, file, protocol=None, *, fix_imports=True)
    1. 将对象(obj)的pickle表示写入打开的文件对象(file)中。
  5. pickle.load(file, *, fix_imports=True, encoding="ASCII", errors="strict")
    1. Read a pickled object representation from the open file object file and return the reconstituted object hierarchy specified therein.

Python object serialization

  1. The pickle module implements binary protocols for serializing and de-serializing a Python object structure.
  2. 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.

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

The module pickletools contains tools for analyzing data streams generated by pickle. pickletools source code has extensive comments about opcodes used by pickle protocols.

There are currently 5 different protocols which can be used for pickling. The higher the protocol used, the more recent the version of Python needed to read the pickle produced.

  1. The pickle module can transform a complex object into a byte stream and it can transform the byte stream into an object with the same internal structure. Perhaps the most obvious thing to do with these byte streams is to write them onto a file, but it is also conceivable to send them across a network or store them in a database. The shelve module provides a simple interface to pickle and unpickle objects on DBM-style database files.

pkl文件是python里面保存文件的一种格式,如果直接打开会显示一堆序列化的东西。
3. pkl文件是什么样的?
4. 为什么要使用pkl文件
5. 怎样使用pkl文件

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值