Reputation: 12522
Octave has a keyboard
function that stops the execution of the script and drops you out into an interactive octave shell, so it is possible to inspect variables at that point and carry our other debugging actions.
Is there anything similar in python?
Upvotes: 2
Views: 218
Reputation: 5993
pdb is the correct answer for debugging, but sometimes it's nice to have the regular REPL:
>>> import code
>>> code.interact(local=locals())
Upvotes: 0
Reputation: 96324
Yes. But you must use the -i
option when running the script:
python -i my_script.py
Actually, you are looking for the python debugger, pdb
. So you must:
import pdb
# some code
my_var = 1
pdb.set_trace()
print(my_var)
And this will drop you into the python debugger. It is quite a broad topic, best to start with reading the docs
Upvotes: 3