# coding=UTF-8
''' python debug method 1
use print function to get output informatino
'''
DEBUG = True
def _debug_(*args, **kwds):
''' depends on DEBUG value, print some function '''
global DEBUG
if DEBUG:
print(args, kwds)
if __name__ == "__main__":
_debug_("this is a test")
# coding=UTF-8
import pdb
def test_function():
''' regard it as a test funcion '''
try:
a = 1
b = 0
c = a / b
except Exception, e:
pdb.set_trace()
return
if __name__ == "__main__":
test_function()
# 输出如下:
> test_debug.py(11)test_function()
-> return
(Pdb) list
6 a = 1
7 b = 0
8 c = a / b
9 except Exception, e:
10 pdb.set_trace()
11 -> return
12
13 if __name__ == "__main__":
14 test_function()
[EOF]
(Pdb) print(e)
integer division or modulo by zero
(Pdb) print(a, b, c)
*** NameError: name 'c' is not defined
(Pdb) print(a, b)
(1, 0)
(Pdb) quit()