在 Python 中也可以像 gcc/gdb 那样调试程序,只要在运行 Python 程序时引入 pdb 模块(假设要调试的程序名为 d.py):
def main():
i, sum = 1, 0
for i in xrange(100):
sum = sum + i
print sum
if __name__ == '__main__':
main()
$ python -m pdb d.py
(Pdb) list
1 #!/usr/bin/python
2
3 def main():
4 i, sum = 1, 0
5 -> for i in xrange(100):
6 B sum = sum + i
7 print sum
8
9 if __name__ == '__main__':
10 main()
[EOF]
(Pdb) list
1 #!/usr/bin/python
2
3 B def main():
4 -> i, sum = 1, 0
5 for i in xrange(100):
6 sum = sum + i
7 print sum
8
9 if __name__ == '__main__':
10 main()
[EOF]
def main():
i, sum = 1, 0
for i in xrange(100):
sum = sum + i
pdb.set_trace()
print sum
if __name__ == '__main__':
main()
新闻热点
疑难解答
图片精选