Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I skip a loop with pdb?

How can I skip over a loop using pdb.set_trace()?

For example,

pdb.set_trace() for i in range(5):      print(i)  print('Done!') 

pdb prompts before the loop. I input a command. All 1-5 values are returned and then I'd like to be prompted with pdb again before the print('Done!') executes.

like image 300
Rhys Avatar asked Jul 18 '11 09:07

Rhys


People also ask

How do I get out of pdb in Python?

from pdb, just type disable N, where N is the breakpoint number you are stuck on. If you don't know the number of your troubling breakpoint, enter tbreak. This will list your breakpoints by number under column "Num" and show whether (yes) or not (no) they are enabled or disabled under the column headed with "Enb."

What is pdb Set_trace ()?

pdb. set_trace (*, header=None) Enter the debugger at the calling stack frame. This is useful to hard-code a breakpoint at a given point in a program, even if the code is not otherwise being debugged (e.g. when an assertion fails). If given, header is printed to the console just before debugging begins.

How do I run a pdb script?

Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint.


1 Answers

Try the until statement.

Go to the last line of the loop (with next or n) and then use until or unt. This will take you to the next line, right after the loop.

http://www.doughellmann.com/PyMOTW/pdb/ has a good explanation

like image 196
shreddd Avatar answered Oct 20 '22 02:10

shreddd