4

Consider the following code:

def inner(a):
    if a == 75:
        raise RuntimeError()
    return a**2

def outer():
    results = []
    for a in range(100):
        results.append(inner(a))
    return results

outer()

In IPython, after the exception was raised, the %debug line magic opens the python debugger at the scope of inner():

In [4]: %debug
> <ipython-input-3-eff43b15b2ef>(3)inner()
      2     if a == 75:
----> 3         raise RuntimeError()
      4     return a**2

ipdb> a
a = 75
ipdb> results
*** NameError: name 'results' is not defined

How can you tell (i)pdb to enter the scope of outer() in order to save the results generated so far?

1 Answer 1

7

I don't think you can directly do it. However, once inside the debugger, you can easily type u (for up) to move the current frame one level up and be inside the outer function. See here for more informations on the commands.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.