呼叫者的帧比当前帧高一帧。您可以
inspect.currentframe().f_back用来查找呼叫者的框架。然后使用inspect.getframeinfo获取调用者的文件名和行号。
import inspectdef hello(): previous_frame = inspect.currentframe().f_back (filename, line_number, function_name, lines, index) = inspect.getframeinfo(previous_frame) return (filename, line_number, function_name, lines, index)print(hello())# ('/home/unutbu/pybin/test.py', 10, '<module>', ['hello()n'], 0)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)