2

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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

5 Comments

Does Python support return from the main thread? or something akin to EXIT /B from cmd? If it does, those would be more appropriate answers to the OP.
So, if I run my script with -i flag, what do I have to do in order to exit to python shell after "my_var=1" line?
@TheIncorrigible1 I'm not sure what you mean. I am not familiar with cmd, but how would that open an interactive shell?
@facha ah, then you must use the python debugger, i.e. import pdb; then pdb.set_trace() after your line.
Great. Just what I needed. Thanks a lot.
0

pdb is the correct answer for debugging, but sometimes it's nice to have the regular REPL:

>>> import code
>>> code.interact(local=locals())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.