import sys def profiler(*args): print(args) def func(arg): return arg sys.setprofile(profiler) list(map(func, "hello")) sys.setprofile(None)