How to debug a function that has been passed as an argument to another function

Viewed 213

I'm new to Python and used to debugging in R. I'm trying to debug my_function when it has been passed as an argument to another function

df.apply(my_function, axis=1)

When I use the debugger (I'm in Spyder V5) I can jump down into the apply function ("down" or "crtl + f11"), but I can't seem to navigate into my_function when it is called from being passed as an argument.

In R I would add browser() to my_function and go from there, but when I try adding ipdb.set_trace(), which I assume is the equivalent, my console hangs without any option to supply input.

I need to examine it in this context because it is breaking when passed as an arg to a specific function, but not others (it actually works in the example function "pd.apply").

1 Answers

You could add breakpoints in Spyder by double-clicking the line number. Then you could run the code using the Debug option or Ctrl+F5.

  • In order to move to the next break point: Continue or Ctrl+F12.
  • To move to the next line: Step or Ctrl+F10
  • To move along the function execution: Step Into or Ctrl+F11
Related