Python Glossary Русский

Python 3.2+disfunction

dis.show_code()

code information

Prints information about a code object — the same text dis.code_info() returns, but straight to the output stream.

Syntax

dis.show_code(x, *, file=None)

It is exactly print(dis.code_info(x)) with a file parameter, and it returns None. When you need the text to parse or check in a test, use code_info(); show_code() is for a quick look in the console. It shows no bytecode — only names, constants and flags — so its output changes far less between versions than that of dis().

Examples

import dis
def f(a, b=2):
    return a + b
dis.show_code(f)  # → ? Name: f, Argument count: 2 и т. д.
import dis, io
def f(a, b=2):
    return a + b
buf = io.StringIO()
dis.show_code(f, file=buf)
print(buf.getvalue() == dis.code_info(f) + '\n')  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy