Python Glossary Русский

all Python 3disfunction

dis.dis()

disassembly

Prints the disassembled bytecode of a function, class, module, code object or a string of source code.

Syntax

dis.dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False)

It prints and returns None: print(dis.dis(f)) shows the listing followed by a stray None; to get the text as a string pass file=io.StringIO() or use Bytecode(f).dis(). Bytecode is a CPython implementation detail and opcodes change every release (in 3.14 LOAD_FAST often becomes LOAD_FAST_BORROW), so never compare listings across versions or build tests on them. Called with no argument it disassembles the last unhandled exception, like distb().

Examples

import dis
def add(a, b):
    return a + b
dis.dis(add)  # → ? листинг байт-кода: опкоды меняются от версии к версии
import dis, io
buf = io.StringIO()
result = dis.dis('x = 1', file=buf)
print(result)  # → None
print('STORE_NAME' in buf.getvalue())  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy