简体   繁体   中英

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 ie 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM