python
python debugging -- exception 발생한 file name, line number 찾기
자유프로그램
2014. 9. 19. 17:18
반응형
python -- exception 발생한 file name, line number 찾기
환경 : windows 7 32bit, python 2.7.8
참조 : http://stackoverflow.com/questions/14519177/python-exception-handling-line-number
https://docs.python.org/2/library/sys.html#sys.exc_info
https://docs.python.org/2/library/traceback.html#
try ... except 구문에서 예외 발생한 경우, 해당 파일명과 발생한 line 번호 찾기
import sys
try:
3/0
except Exception as e :
_, _ , tb = sys.exc_info() # tb -> traceback object
print 'file name = ', __file__
print 'error line No = {}'.format(tb.tb_lineno)
print e
*** 주위 :
windows 8.0 64bit, python 2.7.5 64bit 환경에서 IDLE 에서는 error 발생 !
( NameError: name '__file__' is not defined )
but, terminal 에서 실행시에는 제대로 실행된다!
( 위의 IDLE 의 경우와 다르게 file 경로는 안나옴)
< 결론 >
__file__ 사용 애메함....
반응형