| Python Library Reference |
This module provides a standard interface to extract, format and printstack traces of Python programs. It exactly mimics the behavior ofthe Python interpreter when it prints a stack trace. This is usefulwhen you want to print stack traces under program control, such as in a``wrapper'' around the interpreter.
The module uses traceback objects -- this is the object type that isstored in the variablessys.exc_traceback (deprecated) andsys.last_traceback and returned as the third item fromsys.exc_info().
The module defines the following functions:
None, all entries are printed.Iffile is omitted orNone, the output goes tosys.stderr; otherwise it should be an open file or file-likeobject to receive the output.None, it prints aheader "Traceback (most recent call last):"; (2) it prints theexceptiontype andvalue after the stack trace; (3) iftype isSyntaxError andvalue has theappropriate format, it prints the line where the syntax error occurredwith a caret indicating the approximate position of the error.print_exception(sys.exc_type,sys.exc_value, sys.exc_traceback,limit,file). (Infact, it usessys.exc_info() to retrieve the sameinformation in a thread-safe way instead of using the deprecatedvariables.)print_exception(sys.last_type,sys.last_value, sys.last_traceback,limit,file).None, all entries are extracted. A``pre-processed'' stack trace entry is a quadruple (filename,line number,function name,text) representingthe information that is usually printed for a stack trace. Thetext is a string with leading and trailing whitespacestripped; if the source is not available it isNone.None.sys.last_type andsys.last_value. The return value is a list of strings, eachending in a newline. Normally, the list contains a single string;however, forSyntaxError exceptions, it contains severallines that (when printed) display detailed information about where thesyntax error occurred. The message indicating which exceptionoccurred is the always last string in the list.format_list(extract_tb(tb,limit)).format_list(extract_stack(f,limit)).tb.tb_linenofield of the object, but when optimization is used (the -O flag) thisfield is not updated correctly; this function calculates the correctvalue.| Python Library Reference |