views:

85

answers:

1

Let's say I have the following method (in a class or a module, I don't think it matters):

def someMethod():
    pass

I'd like to access the caller's state at the time this method is called.

traceback.extract_stack just gives me some strings about the call stack.

I'd like something like pdb in which I can set a breakpoint in someMethod() and then type 'u' to go up the call stack and then examine the state of the system then.

Thanks,

Charlie

+1  A: 

I figured it out:

import inspect

def callMe():
tag = ''
frame = inspect.currentframe()
try:
tag = frame.f_back.f_locals['self']._tag
finally:
del frame

return tag