Getting pdb caller information in python

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

def someMethod():
    pass

      

I would like to access the state of the caller while calling this method.

traceback.extract_stack

just gives me a few lines about the call stack.

I would like something like pdb

where I can set a breakpoint at someMethod()

and then type "u" to go to the call stack and then check the system state.

+1


a source to share


1 answer


I understood:



import inspect

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

    return tag

      

+1


a source







All Articles