there is a function keyboard in Matlab/Octave that stops execution and gives control to the keyboard.
It would be useful thing to have around when I have a long running script and need to test a few things. Since Python is interpreted language I guess it should be possible.
Is there such a thing in Python or I should use something more 'Pythonic'? :)
Since Python 3.7 you can use built-in breakpoint() function, as described in PEP 553. In previous Python versions you would use import pdb; pdb.set_trace() as the accepted answer states.
You can use a debugger, such as pdb or ipdb. Once you've acquired the module, just add the following line to your code where you want to stop it:
import ipdb; ipdb.set_trace()
You can use these commands to move through the code once you have control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With