Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - equivalent of Matlab/Octave keyboard function?

Tags:

python

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'? :)

like image 615
NefariousOctopus Avatar asked Jun 15 '26 02:06

NefariousOctopus


2 Answers

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.

like image 97
nirvana-msu Avatar answered Jun 17 '26 14:06

nirvana-msu


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.

like image 29
Dan Cusher Avatar answered Jun 17 '26 15:06

Dan Cusher