3.6 Standard Module traceback
This module provides a standard interface to format and print stack
traces of Python programs. It exactly mimics the behavior of the
Python interpreter when it prints a stack trace. This is useful when
you want to print stack traces under program control, e.g. in a
``wrapper'' around the interpreter.
The module uses traceback objects -- this is the object type
that is stored in the variables sys.exc_traceback and
The module defines the following functions:
- print_tb (traceback[, limit])
Print up to limit stack trace entries from traceback. If
limit is omitted or None, all entries are printed.
- extract_tb (traceback[, limit])
Return a list of up to limit ``pre-processed'' stack trace
entries extracted from traceback. It is useful for alternate
formatting of stack traces. If limit is omitted or None,
all entries are extracted. A ``pre-processed'' stack trace entry is a
quadruple (filename, line number, function name,
line text) representing the information that is usually printed
for a stack trace. The line text is a string with leading and
trailing whitespace stripped; if the source is not available it is
- print_exception (type, value, traceback[, limit])
Print exception information and up to limit stack trace entries
from traceback. This differs from print_tb() in the
following ways: (1) if traceback is not None, it prints a
header "Traceback (innermost last):"; (2) it prints the
exception type and value after the stack trace; (3) if
type is SyntaxError and value has the appropriate
format, it prints the line where the syntax error occurred with a
caret indicating the approximate position of the error.
- print_exc ([limit])
This is a shorthand for `print_exception(sys.exc_type,
sys.exc_value, sys.exc_traceback, limit)'.
- print_last ([limit])
This is a shorthand for `print_exception(sys.last_type,
sys.last_value, sys.last_traceback, limit)'.