2013-11-25 89 views
1

當我運行下面的if/else在調試模式爲什麼pass語句在這個if/else中被執行?

if True: 
    print 'here' 
else: 
    print 'there' 
    pass # breakpoint here 

調試器停在pass聲明。爲什麼pass語句被執行?我知道pass是無關的,但它在else內。

我對Pycharm 2.7.3

UPDATE

如果pass語句是程序的最後一行,並有一個破發點就可以了,調試器中運行的Python 2.7.5將停止在那個pass聲明。我知道它停止了,因爲我可以看到當前的堆棧跟蹤和變量。

但是,如果pass不是最後一行,調試器將不會停在那裏。

+0

您確定調試器在* pass語句後不會停止*嗎? –

回答

6

調試程序在通過語句中沒有中斷。您可以通過後添加一條語句驗證這一點:

$ 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 

可能出現打破那裏,因爲它是文件中的最後一行的調試器?

相關問題