如何获得调用函数的函数名
def get_cur_info(): """Return the frame object for the caller's stack frame.""" try: raise Exception except: f = sys.exc_info()[2].tb_frame.f_back return (f.f_code.co_name, f.f_lineno)
================================================================================
另外,利用python的 inspect 模块中的getframeinfo也可以得到.
- inspect.getframeinfo( frame [, context ])
-
Get information about a frame or traceback object. A 5-tuple is returned, the last five elements of the frame’s frame record.
Changed in version 2.6: Returns a named tuple Traceback(filename, lineno, function,code_context, index).