0

Is there any way to switch to 'interactive' mode within a Python script, similar to the "keyboard" function in Matlab? I am aware of iPython, but I don't think it would allow me to 'pause' at some point in a script, e.g., within a for-loop, switch to interactive mode based on an if-statement.

In Matlab this would simply be something like:

for i = 1:100
    % do stuff
        if i == 55
             keyboard
        end
    % do more stuff
end
skyking
  • 13,817
  • 1
  • 35
  • 57

1 Answers1

3

I think you want the debugger.

import pdb; pdb.set_trace()

This will dump you into a debug session where you can inspect and edit variables, and call functions.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895