# err.py
def foo(s):
n = int(s)
print '>>> n = %d' % n
return 10 / n
def main():
foo('0')
main()
$ python err.py >>> n = 0 Traceback (most recent call last): ... ZeroDivisionError: integer division or modulo by zero
# err.py
def foo(s):
n = int(s)
assert n != 0, 'n is zero!'
return 10 / n
def main():
foo('0')
$ python err.py Traceback (most recent call last): ... AssertionError: n is zero!
$ python -O err.py Traceback (most recent call last): ... ZeroDivisionError: integer division or modulo by zero
# err.py
import logging
s = '0'
n = int(s)
logging.info('n = %d' % n)
print 10 / n
import logging logging.basicConfig(level=logging.INFO)
$ python err.py INFO:root:n = 0 Traceback (most recent call last): File "err.py", line 8, in <module> print 10 / n ZeroDivisionError: integer division or modulo by zero
# err.py s = '0' n = int(s) print 10 / n
$ python -m pdb err.py > /Users/michael/Github/sicp/err.py(2)<module>() -> s = '0'
(Pdb) l 1 # err.py 2 -> s = '0' 3 n = int(s) 4 print 10 / n [EOF]
(Pdb) n > /Users/michael/Github/sicp/err.py(3)<module>() -> n = int(s) (Pdb) n > /Users/michael/Github/sicp/err.py(4)<module>() -> print 10 / n
(Pdb) p s '0' (Pdb) p n 0
(Pdb) n ZeroDivisionError: 'integer division or modulo by zero' > /Users/michael/Github/sicp/err.py(4)<module>() -> print 10 / n (Pdb) q
# err.py import pdb s = '0' n = int(s) pdb.set_trace() # 运行到这里会自动暂停 print 10 / n
$ python err.py > /Users/michael/Github/sicp/err.py(7)<module>() -> print 10 / n (Pdb) p n 0 (Pdb) c Traceback (most recent call last): File "err.py", line 7, in <module> print 10 / n ZeroDivisionError: integer division or modulo by zero
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有