I'm trying to access the frame information for a particular call to the list.sort
method, but i am having trouble.
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
The print-out I get is:
calm_pear
inner
However, the call-order is (outer
, inner
, list.sort
, calm_pear
)
Why isn't out_frames[1].function
something like list.sort
?