[英]why does a pass statement get executed in this if/else?
当我在调试模式下运行以下if / else时
if True:
print 'here'
else:
print 'there'
pass # breakpoint here
调试器在pass
语句上停止。 为什么pass
语句被执行? 我知道pass
是无关紧要的,但是在else
pass
中。
我在Pycharm 2.7.3上运行python 2.7.5
更新
如果pass
语句是程序的最后一行,并且有一个断点,则调试器将在该pass
语句处停止。 我知道它停止了,因为我可以看到当前的堆栈跟踪和变量。
但是,如果pass
不是最后一行,调试器将不会在此处停止。
调试器不会在pass语句上中断。 您可以通过在其后添加一条语句来验证这一点:
$ cat test.py
if True:
print 'here'
else:
print 'there'
pass # breakpoint here
print 'done'
$ python -m pdb test.py
> test.py(1)<module>()
-> if True:
(Pdb++) list
1 -> if True:
2 print 'here'
3 else:
4 print 'there'
5 pass # breakpoint here
6 print 'done'
[EOF]
(Pdb++) break 5
Breakpoint 1 at test.py:5
(Pdb++) continue
here
done
The program finished and will be restarted
调试器可能似乎在此处中断,因为它是文件的最后一行?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.