python pdb调试快捷键_python pdb调试以及sublime3快捷键设置

本文介绍如何使用Python的pdb调试工具,并提供了详细的步骤说明。包括设置断点、条件断点、单步执行等操作,同时展示了如何在Sublime Text 3中配置快捷键来辅助调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

python pdb调试以及sublime3快捷键设置

pdb调试

如果对gdb比较熟悉的话,pdb就很容易上手。以一个demo快速了解常用的调试命令。

def test(a):

while True:

if a > 10:

break

a += 1

return a

if __name__ == '__main__':

test(1)

python -m pdb test.py进入调试环境

b test

在test函数处设置断点,断点号为1

(Pdb) b test

Breakpoint 1 at f:\python\pdb\test.py:1

b 2

在第二行设置断点,断点号为2

(Pdb) b 2

Breakpoint 2 at f:\python\pdb\test.py:2

condition 2 a7

在2号断点处设置条件 a7

b

显示所有断点信息

(Pdb) b

Num Type Disp Enb Where

1 breakpoint keep yes at f:\python\pdb\test.py:1

2 breakpoint keep yes at f:\python\pdb\test.py:2

stop only if a==7

cl 1

去除1号断点,只有cl删除所有断点

(Pdb) cl 1

Deleted breakpoint 1

n

单步跟踪,不进入函数

(Pdb) n

> f:\python\pdb\test.py(8)()

-> if __name__ == '__main__':

(Pdb) n

> f:\python\pdb\test.py(9)()

-> test(1)

s

单步跟踪,进入函数

(Pdb) s

--Call--

> f:\python\pdb\test.py(1)test()

-> def test(a):

c

继续运行在 a==7 条件断点处停止

p a

此时,打印a的值为7

(Pdb) c

> f:\python\pdb\test.py(2)test()

-> while True:

(Pdb) p a

7

a

打印所在函数参数

(Pdb) a

a = 7

l

查看运行到某处代码

(Pdb) l

1 def test(a):

2 B-> while True:

3 if a > 10:

4 break

5 a += 1

6 return a

7 if __name__ == '__main__':

8 test(1)

[EOF]

quit

退出

sublime设置

sublime设置快捷键F5为运行,Ctrl+F5调试。就会对python调试方便很多。

Package Control中下载SublimeREPL(Read-Eval-Print-Loop)

Preferneces -> Key Bingdings-User进行设置

[

{

"keys": [

"f5"

],

"caption": "SublimeREPL: Python - RUN current file",

"command": "run_existing_window_command",

"args": {

"id": "repl_python_run",

"file": "config/Python/Main.sublime-menu"

}

},

{

"keys": [

"ctrl+f5"

],

"caption": "SublimeREPL: Python - PDB current file",

"command": "run_existing_window_command",

"args":

{

"id": "repl_python_pdb",

"file": "config/Python/Main.sublime-menu"

}

}

]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值