Python基礎——8錯誤、調試和測試

捕捉錯誤

try:
    print('try...')
    r = 10 / int('2')
    print('result:', r)
except ValueError as e:
    print('ValueError:', e)
except ZeroDivisionError as e:
    print('ZeroDivisionError:', e)
else:
    print('no error!')
finally:
    print('finally...')
print('END')

調試

import loggingpython

logging.baseConfig(level=logging.INFO)調試

blog

logging.info(‘此處有錯誤’)io

提示優先順序爲:DEBUG INFO WARNING ERROR四種class

相關文章
相關標籤/搜索