0

ys it possible to invoke the keyboard in a python script? E.g. in MATLAB there is way to write

% A lot of code "A"
...
keyboard
% A lot of code "B"
...

in a script, so if you execute the script, it will halt at "keyboard" and you can go on in your MATLAB-shell with the workspace which was build up by code in "A". Is there a similar command in Python?

Tik0
  • 2,499
  • 4
  • 35
  • 50

1 Answers1

2

Take a look at the Python debugger; instead of keyboard you'd use:

import pdb; pdb.set_trace()

and the debugger stops execution and lets you investigate the state of your program.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • If you use ipython, there's also ipdb which runs pdb in the ipython interface. Similar invocation as well `import ipdb; ipdb.set_trace()`. It's a separate package tho, available in PyPI. – Silfheed Oct 24 '13 at 17:53
  • Nice, it is excactly what i was looking for – Tik0 Oct 24 '13 at 17:53