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

30,901

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
30,901
Nick ODell
Author by

Nick ODell

"If finance isn't boring, you're doing it wrong." My favorite sci-fi book is Ethan of Athos, and my favorite fantasy book is Going Postal.

Updated on April 15, 2020

Comments

  • Nick ODell
    Nick ODell about 4 years

    I solved this already, I'm just posting it here because I couldn't figure it out with google, or by reading the docs. I only found it by accident.

    To add a breakpoint, right-click on the line that you want to add a breakpoint on and select "Set Breakpoint". The line will become highlighted. (Note that this only works when you are editing a file; it does not work at the interpreter.)

    This site has a detailed tutorial about using the IDLE debugger.

    On Mac, you need to Control-click instead of right clicking.

  • Nick ODell
    Nick ODell about 13 years
    Where do you submit a patch to documentation? I looked on the IDLE page, but there's no edit button. I looked at the sourceforge page, but it says they moved to python.org. I looked at the main page (and several subpages) but didn't see anything. What am I missing?
  • Ned Deily
    Ned Deily about 13 years
    If you login to the Python bug tracker and then view the linked issue (bugs.python.org/issue10405), you should see a "Comment" text field and a "Choose file" button to select a file to upload.
  • Grezzo
    Grezzo over 7 years
    That's not true
  • Jeffrey Ng
    Jeffrey Ng over 7 years
    @Grezzo, I have updated my comment, was not very proficient back then. thanks for the feedback. hope now it is better. i m trying to help
  • Grezzo
    Grezzo over 7 years
    I appreciate you trying to help :-)
  • Jeffrey Ng
    Jeffrey Ng over 7 years
    Thanks! can you please amend the usefulness of my answer?