Python Glossary Русский

all Python 3tracebackfunction

traceback.format_list()

formatting tracebacks

Turns a list of frames (from extract_tb or extract_stack) into "File …, line …, in …" strings with the source text — ready to print.

Syntax

rows = traceback.format_list(extracted_list)

Every item already contains newlines (the location plus the code line), so print ''.join(rows) rather than calling print per item — otherwise blank lines creep in. Useful when the stack is filtered in code first — dropping third-party frames, say — and shown to a human afterwards. Plain tuples (filename, lineno, name, line) are accepted too.

Examples

import traceback
rows = traceback.format_list([('app.py', 10, 'main', 'run()')])
print(rows)  # → ['  File "app.py", line 10, in main\n    run()\n']

See also

Open in the full glossarydocs.python.orgReport an inaccuracy