我尝试访问list.sort
方法的特定调用的帧信息,但我遇到了麻烦。
import inspect
def calm_pear(x): # compare
cur_frame = inspect.currentframe()
out_frames = inspect.getouterframes(cur_frame)
print(out_frames[0].function) # prints 'calm_pear'
print(out_frames[1].function) # prints 'inner'
print(out_frames[2].function) # prints 'outer'
return id(x)
def outer():
inner()
def inner():
[0, 1].sort(key=calm_pear)
outer() # call outer
我得到的打印件是:
calm_pear
inner
但是,来电订单是(outer
,inner
,list.sort
,calm_pear
)
为什么out_frames[1].function
list.sort
之类的内容不是corrplot
?
答案 0 :(得分:1)
list.sort
是用C语言编写的。用C语言编写的函数不会得到Python堆栈帧。 Python堆栈帧只需要执行用Python编写的代码。
无论您希望通过访问list.sort
不存在的堆栈帧来做什么,您都必须找到其他方法来实现它。