Python dis Module
Example
Inspect bytecode in a stable way:
import dis
def add(a, b):
return a + b
bc = dis.Bytecode(add)
print(isinstance(bc, dis.Bytecode))
print(len(list(bc)) > 0)
Try it Yourself »
Definition and Usage
The dis module supports analysis of CPython bytecode for CPython interpreters.
Use it to obtain bytecode, inspect instructions, and analyze control flow of Python functions and code objects.
Members
Member | Description |
---|---|
Bytecode | Class for creating bytecode objects from functions, code objects, or source. |
code_info() | Return formatted information about the given code object or function. |
dis() | Disassemble functions, methods, or code objects into mnemonics. |
get_instructions() | Iterate over instructions for a function, code object or bytes. |
opmap | Mapping from operation name to numeric opcode. |
opname | List mapping numeric opcode to operation name. |
show_code() | Print details about a code object. |