1
在我的iMac,調試器不給正確的痕跡,運行故障python腳本(在Mac OS塞拉利昂),始終指向代碼的第一有效行作爲例外的原因,沒有調試器啓動時,同時確定了正確的行。有沒有人知道爲什麼會出現這種情況,以及如何解決這個問題?蟒蛇PDB例外
這裏有一個簡單的例子,一個 「找不到文件」 異常:
腳本exception_test.py:
1 # Some dummy lines...
2 a=1
3 b=2
4 c=a+b
5 # Lines casuing the exception:
6 with open("filename","r") as fid:
7 lines=fid.readlines()
當沒有調試器中運行,如python exception_test.py
它產生
Traceback (most recent call last):
File "exception_test.py", line 6, in <module>
with open("filename","r") as fid:
IOError: [Errno 2] No such file or directory: 'filename'
識別正確的路線,即LINE6, 而python -m pdb exception_test.py
和連續c
繼續產量
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pdb.py", line 1314, in main
pdb._runscript(mainpyfile)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pdb.py", line 1233, in _runscript
self.run(statement)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py", line 400, in run
exec cmd in globals, locals
File "<string>", line 1, in <module>
File "exception_test.py", line 2, in <module>
a=1
IOError: [Errno 2] No such file or directory: 'filename'
Uncaught exception. Entering post mortem debugging
指示代碼的第一有效行,即第2行
什麼是您的Python源代碼文件的名稱? –
exception_test.py – momme