traceback.StackSummary

class traceback.StackSummary classmethod extract(frame_gen, *, limit=None, lookup_lines=True, capture_locals=False) Construct a StackSummary object from a frame generator (such as is returned by walk_stack() or walk_tb()). If limit is supplied, only this many frames are taken from frame_gen. If lookup_lines is False, the returned FrameSummary objects will not have read their lines in yet, making the cost of creating the StackSummary cheaper (which may be valuable if it may not actually ge

traceback.print_tb()

traceback.print_tb(tb, limit=None, file=None) Print up to limit stack trace entries from traceback object tb (starting from the caller’s frame) if limit is positive. Otherwise, print the last abs(limit) entries. If limit is omitted or None, all entries are printed. If file is omitted or None, the output goes to sys.stderr; otherwise it should be an open file or file-like object to receive the output. Changed in version 3.5: Added negative limit support.

traceback.print_last()

traceback.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, chain). In general it will work only after an exception has reached an interactive prompt (see sys.last_type).

traceback.format_list()

traceback.format_list(extracted_list) Given a list of tuples 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.

traceback.format_tb()

traceback.format_tb(tb, limit=None) A shorthand for format_list(extract_tb(tb, limit)).

traceback.format_exception_only()

traceback.format_exception_only(etype, value) Format the exception part of a traceback. The arguments are the exception type and value such as given by sys.last_type and sys.last_value. 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 i

traceback.format_stack()

traceback.format_stack(f=None, limit=None) A shorthand for format_list(extract_stack(f, limit)).

traceback.FrameSummary

class traceback.FrameSummary(filename, lineno, name, lookup_line=True, locals=None, line=None) Represent a single frame in the traceback or stack that is being formatted or printed. It may optionally have a stringified version of the frames locals included in it. If lookup_line is False, the source code is not looked up until the FrameSummary has the line attribute accessed (which also happens when casting it to a tuple). line may be directly provided, and will prevent line lookups happening

traceback.clear_frames()

traceback.clear_frames(tb) Clears the local variables of all the stack frames in a traceback tb by calling the clear() method of each frame object. New in version 3.4.

traceback.extract_stack()

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().