pickletools — 用于腌制开发者的工具

源代码: Lib/pickletools.py


此模块包含的各种常量细节密切相关 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 ; ordinary users of the pickle module probably won’t find the pickletools module relevant.

命令行用法

Added in version 3.2.

当援引自命令行时, python -m pickletools will disassemble the contents of one or more pickle files. Note that if you want to see the Python object stored in the pickle rather than the details of pickle format, you may want to use -m pickle instead. However, when the pickle file that you want to examine comes from an untrusted source, -m pickletools is a safer option because it does not execute pickle bytecode.

例如,采用元组 (1, 2) pickled in file x.pickle :

$ python -m pickle x.pickle
(1, 2)
$ python -m pickletools x.pickle
    0: \x80 PROTO      3
    2: K    BININT1    1
    4: K    BININT1    2
    6: \x86 TUPLE2
    7: q    BINPUT     0
    9: .    STOP
highest protocol among opcodes = 2