来自PDB
(Pdb) help l
l(ist) [first [,last]]
List source code for the current file.
Without arguments, list 11 lines around the current line
or continue the previous listing.
With one argument, list 11 lines starting at that line.
With two arguments, list the given range;
if the second argument is less than the first, it is a count.
Run Code Online (Sandbox Code Playgroud)
"继续上一个上市"功能非常好,但是你怎么把它关掉?
Gho*_*r21 25
迟到但希望仍然有用.在pdb中,创建以下别名(您可以将其添加到.pdbrc文件中,以便它始终可用):
alias ll u;;d;;l
Run Code Online (Sandbox Code Playgroud)
然后每当您键入时ll,pdb将从当前位置列出.它的工作方式是向上移动堆栈然后向下移动堆栈,重置"l"以显示当前位置.(如果您位于堆栈跟踪的顶部,则无效.)
小智 6
如果你使用epdb而不是pdb,你可以使用"l"继续前进,就像在pdb中一样,然后使用"l".返回当前行号,"l-"返回文件.您也可以使用#直到给定的行继续.Epdb也提供了许多其他细节.需要远程调试吗?尝试serve()代替set_trace()然后telnet(端口8080是默认端口).
import epdb
epdb.serve()
Run Code Online (Sandbox Code Playgroud)
你可以猴子修补它以获得你想要的行为。例如,下面是一个完整的脚本,它将“reset_list”或“rl”命令添加到 pdb:
import pdb
def Pdb_reset_list(self, arg):
self.lineno = None
print >>self.stdout, "Reset list position."
pdb.Pdb.do_reset = Pdb_reset_list
pdb.Pdb.do_rl = Pdb_reset_list
a = 1
b = 2
pdb.set_trace()
print a, b
Run Code Online (Sandbox Code Playgroud)
可以想象,我们可以对标准list命令进行猴子修补,以不保留 lineno 历史记录。
编辑:这是这样一个补丁:
import pdb
Pdb = pdb.Pdb
Pdb._do_list = Pdb.do_list
def pdb_list_wrapper(self, arg):
if arg.strip().lower() in ('r', 'reset', 'c', 'current'):
self.lineno = None
arg = ''
self._do_list(arg)
Pdb.do_list = Pdb.do_l = pdb_list_wrapper
a = 1
b = 2
pdb.set_trace()
print a, b
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3252 次 |
| 最近记录: |