Skip to content

Commit 314c12d

Browse files
authored
练习调试程序
1 parent 5adefb4 commit 314c12d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test27.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
'练习调试程序'
5+
6+
__author__ = 'sergiojune'
7+
import logging
8+
import pdb
9+
# 这个标明打印信息的类别,不标明不会打印具体的错误信息
10+
logging.basicConfig(level=logging.INFO)
11+
12+
13+
def foo(n):
14+
# if n == 0:
15+
# # 这个麻烦,可以用断言,这样没有输出
16+
# print('n is zero !')
17+
# else:
18+
# return 10 / n
19+
# 这个当条件为false时,就会执行后面语句,并抛出assertionError
20+
assert n != 0, 'n is zero !'
21+
return 10/n
22+
23+
24+
foo(1)
25+
26+
s = '0'
27+
n = int(s)
28+
# 开发中用这个较多
29+
logging.info('n = %d' % n)
30+
print(10 / n)
31+
32+
# 还可以用pdb进行调试
33+
s = '0'
34+
n = int(s)
35+
# 这个就是设置断点
36+
pdb.set_trace()
37+
logging.info('n = %d' % n)
38+
print(10 / n)

0 commit comments

Comments
 (0)