tkj80
tkj80

Reputation: 211

How to debug function declared on Spyder IPython console

how do I debug and step into a function that I declared interactively on Spyder Ipython?

As an example, I have the following function that I declare interactively:

def my_function(x,y):
    w = x*2
    z = y*2
    return w+z

I did some reading online, it looks like to debug I have to load the py script first. As an example:

$ python -m pdb hello.py

Can I debug without loading the script?

I want to call my_function(1,2) and see what values are the w and z.

Thank you!

Upvotes: 2

Views: 1205

Answers (1)

Carlos Cordoba
Carlos Cordoba

Reputation: 34156

You need to add the following line inside your function

def my_function(x,y):
    import pdb; pdb.set_trace()
    w = x*2
    z = y*2
    return w+z

Then after you call it in the console like this

my_function(1, 2)

you'll be taken to the debugger automatically.

Upvotes: 2

Related Questions