import inspect def fun1(): fun2() def fun2(): who=inspect.stack()[1][3] # 记录被谁调用了 print(f"{who}") print(type(who)) fun1() ''' 'fun1' <class 'list'> '''