Python Glossary Русский

all Python 3pdbfunction

pdb.run()

running under the debugger

Runs a string of code under the debugger: the (Pdb) prompt appears before the first line.

Syntax

pdb.run(statement, globals=None, locals=None)

Without globals the code runs in the __main__ namespace, so variables created by the string show up in your module. It returns None; runeval() gives you the value of an expression. Commands are read from sys.stdin, so in a program fed data on stdin (as in an autograder) the debugger eats the task's input. The old name pdb.runctx(statement, globals, locals) is the same function, kept for backward compatibility.

Examples

import io, sys, pdb
sys.stdin = io.StringIO('c\n')  # команды отладчику вместо клавиатуры
sys.stdout = log = io.StringIO()
pdb.run('total = sum(range(5))')
sys.stdout = sys.__stdout__
print(total)  # → 10 — переменная попала в __main__

See also

Open in the full glossarydocs.python.orgReport an inaccuracy