32.13. pickletools — pickle 开发者工具集¶
2.3 新版功能.
源代码: Lib/pickletools.py
This module contains various constants relating to the intimate details of the
pickle module, some lengthy comments about the implementation, and a few
useful functions for analyzing pickled data. The contents of this module are
useful for Python core developers who are working on the pickle and
cPickle implementations; ordinary users of the pickle module
probably won’t find the pickletools module relevant.
-
pickletools.dis(pickle, out=None, memo=None, indentlevel=4)¶ Outputs a symbolic disassembly of the pickle to the file-like object out, defaulting to
sys.stdout. pickle can be a string or a file-like object. memo can be a Python dictionary that will be used as the pickle’s memo; it can be used to perform disassemblies across multiple pickles created by the same pickler. Successive levels, indicated byMARKopcodes in the stream, are indented by indentlevel spaces.
-
pickletools.genops(pickle)¶ 提供包含 pickle 中所有操作码的 iterator,返回一个
(opcode, arg, pos)三元组的序列。 opcode 是OpcodeInfo类的一个实例;arg 是 Python 对象形式的 opcode 参数的已解码值;pos 是 opcode 所在的位置。 pickle 可以是一个字符串或一个文件类对象。
-
pickletools.optimize(picklestring)¶ 在消除未使用的
PUT操作码之后返回一个新的等效 pickle 字符串。 优化后的 pickle 将更为简短,耗费更为的传输时间,要求更少的存储空间并能更高效地解封。2.6 新版功能.
