Code Editor

User guideCode Editor for Mac

Debug a Python script

Pause inside the sample script and follow a value into a function.

Set the first breakpoint

  1. In the sample project open debug_me.py. Find total = add(total, counts[0]) and click in the margin beside that line. A breakpoint marker appears.
  2. Select the Local Python configuration for debug_me.py, then click Debug or press ⇧⌘R. Execution pauses before that assignment.
  3. In the Debug inspector, inspect Variables. At this point total is 0 and counts contains 1, 2 and 3.
Python debugger paused with source and variable inspector visible
The highlighted line shows where execution will resume.

Follow the value through the call

Press Step Into (F7) to enter add. Check the arguments total and value. Step Over (F6) executes the assignment to result. Step Out (F8) returns to the caller. To run the call as a single operation instead, use Step Over on the original assignment.

Choose Continue to reach the next breakpoint or finish the script. With the sample’s default arguments and no further breakpoints, Console ends with total 6 and done 3.

If Debug is unavailable

Check the selected configuration in the top bar. Debug applies to a Local Python configuration. Stop any run already in progress, then select the file’s configuration again. If the script finishes immediately, make sure its path matches the open file and the breakpoint is enabled on a line the script reaches.