def func(frame, event, arg): print(frame.f_lineno, event) return func import sys sys.settrace(func) sys._getframe().f_trace = func [ 1, 2, ]