Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取调用list.sort()的帧数据?_Python_Python 3.x_Introspection_Inspect_Stack Frame - Fatal编程技术网

Python 如何获取调用list.sort()的帧数据?

Python 如何获取调用list.sort()的帧数据?,python,python-3.x,introspection,inspect,stack-frame,Python,Python 3.x,Introspection,Inspect,Stack Frame,我正在尝试访问对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[

我正在尝试访问对
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
但是,调用顺序是(
外部
内部
列表.排序
平静


为什么[1]框架中没有
。函数
类似于
列表。排序

列表。排序
是用C编写的。用C编写的函数不会得到Python堆栈框架。Python堆栈框架仅用于执行用Python编写的代码

无论您希望通过访问
list.sort
不存在的堆栈帧来执行什么操作,您都必须找到其他方法来执行