Python 3.5+tracebackterm
traceback.FrameSummary
frames and stack
One traceback frame: file name, line number, function name and source line — a snapshot with no reference to the live frame or its variables.
Syntax
traceback.FrameSummary(filename, lineno, name, *, lookup_line=True, locals=None, line=None)
StackSummary objects from extract_tb() and extract_stack() are made of them. Unlike a frame object it keeps no local variables, so a list of FrameSummary can be stored and passed around without keeping everything the functions held alive. It unpacks like a four-item tuple (filename, lineno, name, line), which keeps old code working from the days when extract_tb returned tuples. The line text is read lazily through linecache: if the file has been edited meanwhile, you get the new line.
Examples
import traceback
def boom():
return 1 / 0
try:
boom()
except ZeroDivisionError as e:
fs = traceback.extract_tb(e.__traceback__)[-1]
print(fs.name, fs.lineno, fs.line) # → boom 3 return 1 / 0
filename, lineno, name, line = fs
print(name == fs.name) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy