跳过收益声明

Eog*_*anM 5 python generator pdb

在Python调试器(pdb)中时,我想跳过yield语句,但接下来按下(n)会将我带到yield 的目的地,即生成器的使用者。我想转到在生成器中执行的下一行。有什么办法吗?

我正在使用Python 2.6

War*_*rty -2

如果您的调试器允许您使用断点并更改变量值,那么就像[伪代码]一样简单

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;
Run Code Online (Sandbox Code Playgroud)

请注意,通常不能将断点粘贴在空行上。不过,您必须将其放在 if 语句之前。