facha
facha

Reputation: 12522

How to stop python script execution and end up in python shell

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

Answers (2)

Brett Beatty
Brett Beatty

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

juanpa.arrivillaga
juanpa.arrivillaga

Reputation: 96324

Yes. But you must use the -i option when running the script:

python -i my_script.py

Edit

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

Related Questions