Python-pdb跳过代码(如“不执行”) [英] Python-pdb skip code (as in "not execute")

查看:471
本文介绍了Python-pdb跳过代码(如“不执行”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在pdb中完全跳过一两行?

Is there a way to skip a line or two altogether in pdb?

说我有一个pdb会话:

Say I have a pdb session:

> print 10
  import pdb; pdb.set_trace()
  destroy_the_universe() # side effect
  useful_line()

并且我想直接进入有用的行()而不必再次调用pdb()或破坏宇宙。
是否可以跳过(即不执行代码)

And I want to go straight to useful_line() WITHOUT invoking pdb() once again, or destroying the universe. Is there a way to skip (i.e. not execute code) what is between

print 10和有用的行()之间的内容?

print 10 and useful_line()?

推荐答案

使用 j / jump 命令:

test.py包含:

test.py contains:

def destroy_the_universe():
    raise RuntimeError("Armageddon")

def useful_line():
    print("Kittens-r-us")

print(10)
import pdb; pdb.set_trace()
destroy_the_universe()
useful_line()

然后:

C:\Temp>c:\python34\python test.py
10
> c:\temp\test.py(9)<module>()
-> destroy_the_universe()
(Pdb) l
  4     def useful_line():
  5         print("Kittens-r-us")
  6
  7     print(10)
  8     import pdb; pdb.set_trace()
  9  -> destroy_the_universe()
 10     useful_line()
[EOF]
(Pdb) j 10
> c:\temp\test.py(10)<module>()
-> useful_line()
(Pdb) c
Kittens-r-us

这篇关于Python-pdb跳过代码(如“不执行”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆