开发者

Stepping over a yield statement

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 generat开发者_如何学JAVAor. Is there any way to do this?

I'm using Python 2.6


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜