Python 3.4+tracemallocterm
tracemalloc.Frame
traces and frames
A frame of a tracemalloc trace: the filename and the line number lineno of the allocation.
Syntax
frame.filename, frame.lineno
It stores only the file and the line — no function name and no source text; Traceback.format() fetches the text through linecache, so if the file changed after start-up the new line gets printed. A Frame is immutable and hashable, so it works as a dict key for custom grouping. tracemalloc creates it, not the user.
Examples
import tracemalloc
tracemalloc.start()
data = bytes(1000)
frame = tracemalloc.get_object_traceback(data)[0]
print(type(frame).__name__, frame.lineno, frame.filename == __file__) # → Frame 3 True
print({frame: 'here'}[frame]) # → here
tracemalloc.stop()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy