官术网_书友最值得收藏!

Within a Python script

The previous two techniques will start the debugger at the beginning of a Python program. But this third technique is best for long-running processes. To start the debugger within a script, use set_trace().

Now, modify your pdb_example.py file as follows:

import pdb
class Student:
def __init__(self, std):
self.count = std

def print_std(self):
for i in range(self.count):
pdb.set_trace()
print(i)
return

if __name__ == '__main__':
Student(5).print_std()

Now, run the program as follows:

student@ubuntu:~$ python3 pdb_example.py
> /home/student/pdb_example.py(10)print_std()
-> print(i)
(Pdb) continue
0
> /home/student/pdb_example.py(9)print_std()
-> pdb.set_trace()
(Pdb)

set_trace() is a Python function, therefore you can call it at any point in your program.

So, these are the three ways by which you can start a debugger.

主站蜘蛛池模板: 桦川县| 江山市| 伊宁县| 吉安县| 正阳县| 慈溪市| 哈尔滨市| 万安县| 杂多县| 祥云县| 临湘市| 赣榆县| 巩义市| 固安县| 楚雄市| 荣成市| 元江| 扶绥县| 西乌珠穆沁旗| 公主岭市| 铜山县| 田林县| 永新县| 政和县| 泸溪县| 白玉县| 隆林| 曲沃县| 滁州市| 阳山县| 安龙县| 苗栗县| 彩票| 克什克腾旗| 济阳县| 隆林| 道孚县| 景泰县| 都安| 吴堡县| 乡城县|