Reputation: 3
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
Upvotes: 0
Views: 93
Reputation: 599610
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.
Upvotes: 3