Context:
I am running some python code through PDB (Python debugger). When I set and then hit a breakpoint, I can check the local variables using:
(Pdb) locals()
This displays a nice pair of names, pairs of values โโof local variables in the current area in which I am paused. Fine!
I also see a stack trace with the PDB where command, which leads to something like this:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py(400)run() -> exec cmd in globals, locals <string>(1)<module>() .../main.py(116)<module>() -> run() .../main.py(104)run() -> res = quicksort(res) > .../main.py(68)quicksort() -> if len(v) <= 1:
In this example output, I am suspended in the quicksort() function, which was called by the run() function.
So far so good.
Question:
If I can check the local variables of the quicksort() function with a call to locals() , how can I similarly check the local variables of the run() function?
In other words, how can I check the local variables of a function that is nested on a call stack?
Important clarification . I DO NOT want to continue or step in run() to check its local variables. I want to check (from my current, suspended perspective) the local variables in the run() stack frame that are currently nested on the call stack.
python debugging pdb
Todd ditchendorf
source share