pydoc > traceback

๐Ÿ“– NAME

traceback - Extract, format and print information about Python stack traces.

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿ“ค Print current exceptionprint_exc()Shortcut to print exception info from sys.exc_info()
๐Ÿ“„ Get exception as stringformat_exc()Like print_exc() but returns a string
๐Ÿ“‹ Extract stack framesextract_tb(tb)Return StackSummary of pre-processed entries from traceback
๐Ÿ“œ Format stack listformat_list(list)Format a list of FrameSummary objects for printing
๐Ÿ–จ๏ธ Print stack traceprint_stack()Print a stack trace from current invocation point
๐Ÿ” Extract current stackextract_stack()Extract raw traceback from current stack frame
โš ๏ธ Format exception with chainformat_exception(exc, value, tb)Format stack trace and exception information
๐Ÿงน Clear frame localsclear_frames(tb)Clear all references to local variables in traceback frames

๐Ÿ”— MODULE REFERENCE

https://docs.python.org/3.10/library/traceback.html

The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.

๐Ÿ—‚๏ธ CLASSES

builtins.list(builtins.object)
    StackSummary
builtins.object
    FrameSummary
    TracebackException

๐Ÿ“„ FrameSummary

class FrameSummary(builtins.object)

FrameSummary(filename, lineno, name, *, lookup_line=True, locals=None, line=None)

A single frame from a traceback.

๐Ÿงฉ Methods

๐Ÿ”’ Readonly properties

๐Ÿ“ Data descriptors

๐Ÿ“ฆ Data and other attributes

๐Ÿ“š StackSummary

class StackSummary(builtins.list)

StackSummary(iterable=(), /)

A stack of frames.

Method resolution order:

  1. StackSummary
  2. builtins.list
  3. builtins.object

๐Ÿงฉ Methods

๐Ÿ—๏ธ Class methods

๐Ÿ“ Data descriptors

๐Ÿ“ฆ Inherited from builtins.list

๐Ÿ—๏ธ Class methods inherited from builtins.list

๐Ÿงฐ Static methods inherited from builtins.list

๐Ÿ“ฆ Data and other attributes inherited from builtins.list

โš ๏ธ TracebackException

class TracebackException(builtins.object)

TracebackException(exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, _seen=None)

An exception ready for rendering.

The traceback module captures enough attributes from the original exception to this intermediary form to ensure that no references are held, while still being able to fully print or format it.

Use from_exception to create TracebackException instances from exception objects, or the constructor to create TracebackException instances from individual components.

๐Ÿงฉ Methods

๐Ÿ—๏ธ Class methods

๐Ÿ“ Data descriptors

๐Ÿ“ฆ Data and other attributes

๐Ÿ”ง FUNCTIONS

๐Ÿงน clear_frames(tb)

Clear all references to local variables in the frames of a traceback.

๐Ÿ“‹ extract_stack(f=None, limit=None)

Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional f and limit arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame.

๐Ÿ“‡ extract_tb(tb, limit=None)

Return a StackSummary object representing a list of pre-processed entries from traceback. This 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 FrameSummary object containing attributes filename, lineno, name, and line representing the information that is usually printed for a stack trace. The line is a string with leading and trailing whitespace stripped; if the source is not available it is None.

๐Ÿ“„ format_exc(limit=None, chain=True)

Like print_exc() but return a string.

โš ๏ธ format_exception(exc, /, value=<implicit>, tb=<implicit>, limit=None, chain=True)

Format a stack trace and the exception information. The arguments have the same meaning as the corresponding arguments to print_exception(). The return value is a list of strings, each ending in a newline and some containing internal newlines. When these lines are concatenated and printed, exactly the same text is printed as does print_exception().

๐Ÿ” format_exception_only(exc, /, value=<implicit>)

Format the exception part of a traceback. The return value is a list of strings, each ending in a newline. Normally, the list contains a single string; however, for SyntaxError exceptions, it contains several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is always the last string in the list.

๐Ÿ“œ format_list(extracted_list)

Format a list of tuples or FrameSummary objects for printing. Given a list of tuples or FrameSummary objects as returned by extract_tb() or extract_stack(), return a list of strings ready for printing. Each string in the resulting list corresponds to the item with the same index in the argument list. Each string ends in a newline; the strings may contain internal newlines as well, for those items whose source text line is not None.

๐Ÿ“‹ format_stack(f=None, limit=None)

Shorthand for format_list(extract_stack(f, limit)).

๐Ÿ“‡ format_tb(tb, limit=None)

A shorthand for format_list(extract_tb(tb, limit)).

๐Ÿ–จ๏ธ print_exc(limit=None, file=None, chain=True)

Shorthand for print_exception(*sys.exc_info(), limit, file).

๐Ÿ–จ๏ธ print_exception(exc, /, value=<implicit>, tb=<implicit>, limit=None, file=None, chain=True)

Print exception up to limit stack trace entries from tb to file. This differs from print_tb() in the following ways: (1) if traceback is not None, it prints a header "Traceback (most recent call 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 on the next line indicating the approximate position of the error.

โฎ๏ธ print_last(limit=None, file=None, chain=True)

This is a shorthand for print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file).

๐Ÿ–จ๏ธ print_stack(f=None, limit=None, file=None)

Print a stack trace from its invocation point. The optional f argument can be used to specify an alternate stack frame at which to start. The optional limit and file arguments have the same meaning as for print_exception().

๐Ÿ–จ๏ธ print_tb(tb, limit=None, file=None)

Print up to limit stack trace entries from the traceback tb. If limit is omitted or None, all entries are printed. If file is omitted or None, the output goes to sys.stderr; otherwise file should be an open file or file-like object with a write() method.

๐Ÿšถ walk_stack(f)

Walk a stack yielding the frame and line number for each frame. This will follow f.f_back from the given frame. If no frame is given, the current stack is used. Usually used with StackSummary.extract.

๐Ÿšถ walk_tb(tb)

Walk a traceback yielding the frame and line number for each frame. This will follow tb.tb_next (and thus is in the opposite order to walk_stack). Usually used with StackSummary.extract.

๐Ÿ“Š DATA

__all__ = ['extract_stack', 'extract_tb', 'format_exception', 'format_...']

๐Ÿ“ FILE

/usr/lib/python3.10/traceback.py

traceback
๐Ÿ“– NAME ๐Ÿš€ Quick Reference ๐Ÿ”— MODULE REFERENCE ๐Ÿ—‚๏ธ CLASSES
๐Ÿ“„ FrameSummary ๐Ÿ“š StackSummary โš ๏ธ TracebackException
๐Ÿ”ง FUNCTIONS
๐Ÿงน clear_frames(tb) ๐Ÿ“‹ extract_stack(f=None, limit=None) ๐Ÿ“‡ extract_tb(tb, limit=None) ๐Ÿ“„ format_exc(limit=None, chain=True) โš ๏ธ format_exception(exc, /, value=<implicit>, tb=<implicit>, limit=None, chain=True) ๐Ÿ” format_exception_only(exc, /, value=<implicit>) ๐Ÿ“œ format_list(extracted_list) ๐Ÿ“‹ format_stack(f=None, limit=None) ๐Ÿ“‡ format_tb(tb, limit=None) ๐Ÿ–จ๏ธ print_exc(limit=None, file=None, chain=True) ๐Ÿ–จ๏ธ print_exception(exc, /, value=<implicit>, tb=<implicit>, limit=None, file=None, chain=True) โฎ๏ธ print_last(limit=None, file=None, chain=True) ๐Ÿ–จ๏ธ print_stack(f=None, limit=None, file=None) ๐Ÿ–จ๏ธ print_tb(tb, limit=None, file=None) ๐Ÿšถ walk_stack(f) ๐Ÿšถ walk_tb(tb)
๐Ÿ“Š DATA ๐Ÿ“ FILE

Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-02 22:07 @216.73.216.239
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^