Based on wim's solution, here is my function:
def my_tracer(frame, event, arg=None):
# only respond to 'call' events
if event != 'call':
return
# extracts frame code
code = frame.f_code
# extracts calling function name
func_name = code.co_name
# skip 'noise' methods such as __init__ or writes
if func_name in ['__init__', 'write']:
return
# extracts the line number
line_no = frame.f_lineno
print(f"A {event} encountered in {func_name}() at line number {line_no} ")
return my_tracer
And then
if __name__ == "__main__":
settrace(my_tracer)