2

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").

  • Spyder also let's users set breakpoints. Or consider using VSCode + debugging mode. – sotmot Jan 09 '22 at 13:18
  • 1
    I was having problems with my breakpoints being ignored, but I realized they only break when run in debug ("ctrl + f5") and not when run normally. That confused me because in R when I want to break with "browser()" I just run the function normally. If only I knew a way to begin debugging from a specific point in the middle of the script rather than starting from the top. I'll accept your answer if you make one. Thanks! – hashtagyoloswag Jan 09 '22 at 13:49

1 Answers1

0

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
sotmot
  • 1,256
  • 2
  • 9
  • 21