views:

80

answers:

2

When in the Python debugger (pdb) I want to step over a yield statement, but hitting (n) for next brings me to the destination of the yield i.e. the consumer of the generator. I want to go to the next line that is executed within the generator. Is there any way to do this?

I'm using Python 2.6

A: 

If your debugger allows you to use breakpoints and change variable values when you're there, it's as simple as [in pseudo code]

Set Boolean yieldValue to true;
[breakpoint after that line is executed, you can set yieldValue to false here]
if yieldValue, yield value;

in other words:

bool yieldValue = true;
[breakpoint here]
if(yieldValue) yield value;

Note that you usually can't stick a breakpoint on an empty line. You'll have to stick it before the if statement, though.

ItzWarty
A: 

In debuggers, generally you want to "step" (s) into a function in this case, rather than "next" (n).

"Next" executes the next line in the scope you're looking at; "step" brings you into the next scope down, the generator in this case, which sounds like what you want to do.

Vicki Laidler
No, he's saying that *within the generator*, he wants to step over a yield and land on the line following it, which is exactly what "next" should be doing. ("1 comment per 15 seconds, timer reset"? Ugh, whoever thought that was a good idea needs to be shot...)
Glenn Maynard