pickletools - pydoc - phpman

Look up a command

 

Markdown Format | JSON API | MCP Server Tool


pickletools
NAME MODULE REFERENCE DESCRIPTION FUNCTIONS DATA FILE
Help on module pickletools:

NAME
    pickletools - "Executable documentation" for the pickle module.

MODULE REFERENCE
    https://docs.python.org/3.10/library/pickletools.html

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

DESCRIPTION
    Extensive comments about the pickle protocols and pickle-machine opcodes
    can be found here.  Some functions meant for external use:

    genops(pickle)
       Generate all the opcodes in a pickle, as (opcode, arg, position) triples.

    dis(pickle, out=None, memo=None, indentlevel=4)
       Print a symbolic disassembly of a pickle.

FUNCTIONS
    dis(pickle, out=None, memo=None, indentlevel=4, annotate=0)
        Produce a symbolic disassembly of a pickle.

        'pickle' is a file-like object, or string, containing a (at least one)
        pickle.  The pickle is disassembled from the current position, through
        the first STOP opcode encountered.

        Optional arg 'out' is a file-like object to which the disassembly is
        printed.  It defaults to sys.stdout.

        Optional arg 'memo' is a Python dict, used as the pickle's memo.  It
        may be mutated by dis(), if the pickle contains PUT or BINPUT opcodes.
        Passing the same memo object to another dis() call then allows disassembly
        to proceed across multiple pickles that were all created by the same
        pickler with the same memo.  Ordinarily you don't need to worry about this.

        Optional arg 'indentlevel' is the number of blanks by which to indent
        a new MARK level.  It defaults to 4.

        Optional arg 'annotate' if nonzero instructs dis() to add short
        description of the opcode on each line of disassembled output.
        The value given to 'annotate' must be an integer and is used as a
        hint for the column where annotation should start.  The default
        value is 0, meaning no annotations.

        In addition to printing the disassembly, some sanity checks are made:

        + All embedded opcode arguments "make sense".

        + Explicit and implicit pop operations have enough items on the stack.

        + When an opcode implicitly refers to a markobject, a markobject is
          actually on the stack.

        + A memo entry isn't referenced before it's defined.

        + The markobject isn't stored in the memo.

        + A memo entry isn't redefined.

    genops(pickle)
        Generate all the opcodes in a pickle.

        'pickle' is a file-like object, or string, containing the pickle.

        Each opcode in the pickle is generated, from the current pickle position,
        stopping after a STOP opcode is delivered.  A triple is generated for
        each opcode:

            opcode, arg, pos

        opcode is an OpcodeInfo record, describing the current opcode.

        If the opcode has an argument embedded in the pickle, arg is its decoded
        value, as a Python object.  If the opcode doesn't have an argument, arg
        is None.

        If the pickle has a tell() method, pos was the value of pickle.tell()
        before reading the current opcode.  If the pickle is a bytes object,
        it's wrapped in a BytesIO object, and the latter's tell() result is
        used.  Else (the pickle doesn't have a tell(), and it's not obvious how
        to query its current position) pos is None.

    optimize(p)
        Optimize a pickle string by removing unused PUT opcodes

DATA
    __all__ = ['dis', 'genops', 'optimize']
    __test__ = {'disassembler_memo_test': '\n>>> import pickle\n>>> import...

FILE
    /usr/lib/python3.10/pickletools.py



Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 05:14 @216.73.216.198 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 TransitionalValid CSS!

^_back to top