On this page
dis.Bytecode
Up: dis | Next: dis.code_info
Rel: dis.code_info, dis.dis, dis.disassemble, dis.disco
Ref: docs.python.org — dis.Bytecode
Tags: #public #python3 #stdlib #dis
Import
import dis
from dis import Bytecode
Signature & Overview
dis.Bytecode(x, *, first_line=None, current_offset=None, show_caches=False, adaptive=False, show_offsets=False, show_positions=False)
The bytecode operations of a piece of code Instantiate this with a function, method, other compiled object, string of code, or a code object (as returned by compile()).
Methods & Attributes
Bytecode.dis(self)— Return a formatted view of the bytecode operations.Bytecode.from_traceback(tb, *, show_caches=False, adaptive=False)— Construct a Bytecode from the given tracebackBytecode.info(self)— Return formatted information about the code object.
Usage
import dis
bc = dis.Bytecode(lambda x: x + 1)
opnames = [ins.opname for ins in bc]
assert "RETURN_VALUE" in opnames
Gotchas
- Cleanest object-oriented API for inspecting bytecode: Iterate over
Instructionobjects or callbc.dis()for formatted text.
REPL Inspect
from dis import Bytecode
help(Bytecode)
Linked from
- tuts/python3/stdlib_module/dis
- tuts/python3/stdlib_module/dis/code_info
- tuts/python3/stdlib_module/dis/dis
- tuts/python3/stdlib_module/dis/disassemble
- tuts/python3/stdlib_module/dis/disco
- tuts/python3/stdlib_module/dis/distb
- tuts/python3/stdlib_module/dis/findlabels
- tuts/python3/stdlib_module/dis/findlinestarts
- tuts/python3/stdlib_module/dis/get_instructions
- tuts/python3/stdlib_module/dis/Instruction
- tuts/python3/stdlib_module/dis/show_code
- tuts/python3/stdlib_module/dis/stack_effect
Related notes
- tuts/python3/stdlib_module/dis/code_info Linked here; links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/dis Linked here; links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/disassemble Linked here; links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/disco Linked here; links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/distb links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/findlabels links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/findlinestarts links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/get_instructions links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/Instruction links to this page; shared tags: #dis, #stdlib
- tuts/python3/stdlib_module/dis/show_code links to this page; shared tags: #dis, #stdlib