Reputation: 544
When in pdb mode I often want to step into a function. Here is a situation that illustrates what I might do. Given the code:
def f(x):
print('doing important stuff..')
result = g(x) + 2
return result
def g(x):
print('some cool stuff going on here, as well')
0 / 0 # oops! a bug
return x + 5
Now, assume I set a breakpoint between the print('doing important stuff...')
and result = g(x) + 2
. So now, f(x)
looks like this:
def f(x):
print('doing important stuff..')
__import__('pdb').set_trace() # or something similar..
result = g(x) + 2
return result
And then I call the function f(x)
with x=5
, expecting to get a result 12
. When called, I end up in an interactive pdb session on the second line in f
. Hitting n
will give me the error (in this case a ZeroDivisionError). Now, I want to step into the g(x)
function interactively to see what the error might be. Is it somehow possible to do that while not "moving" the breakpoint in g(x)
and re-running everything? I simply want to enter the function g
on the first line while still being in pdb mode.
I've searched for previous SO questions and answers + looked up the documentation and still haven't found anything that addresses this particular situation.
Upvotes: 40
Views: 44959