Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add breakpoints to a Python program in IDLE?

People also ask

How do you set a breakpoint to a program?

You can set a breakpoint at a line number, using the stop at command, where n is a source code line number and filename is an optional program file name qualifier. If the line specified is not an executable line of source code, dbx sets the breakpoint at the next executable line.

How do I debug Python program in idle?

To do so, select Debug → Debugger from the Python IDLE menu bar. In the interpreter, you should see [DEBUG ON] appear just before the prompt ( >>> ), which means the interpreter is ready and waiting. In this window, you can inspect the values of your local and global variables as your code executes.

How do you insert a breakpoint in Python?

You can insert a breakpoint with the breakpoint() function at any position in your code . This is new in Python 3.7, and is equivalent to the older import pdb; pdb. set_trace() command. # my_script.py a = int(0.1) b = 3.0 c = a + b breakpoint() # a lot of more code here...

Does Python Idle have a debugger?

IDLE has a debugger built into it. It is very useful for stepping through a program and watching the variables change values.


Completing the answer supplied by the OP: after setting the breakpoint - you must turn on IDLE's debug mode (using debug --> debugger). When you run the program, press "Go" in the debug window that opens up and IDLE will stop at the breakpoint.


There is an open Python issue about the lack of documentation for IDLE breakpoints. Contributions welcome!

Update: The on-line documentation and the IDLE help files (for 2.7.4, 3.2.4, and 3.3.0) have been updated, with Nick's help.


You can set breakpoint before it is run.

  1. Set the breakpoint by right clicking on the relevant line of your program
  2. On your python shell, look for Debug - [Debug On] will be shown in your IDLE Python shell
  3. Go back to your program and press F5(hotkey) to run the program, it will stop in the relevant break line(s)
  4. If you want to look at some global variables or line of codes, you can check the box in the debugger

Just adding to this answer (would've commented but for the rules that say I don't have enough reputation to do so): On the Mac you must control-click. The normal "right-click" at least for the trackpad does not work to bring up the contextual menu with the option to set a breakpoint.