我想用bpython解释器进行调试。 我的问题类似于“Is it possible to go into ipython from code?”,它询问了关于ipython。是否可以使用bpython作为完整的调试器?
如果您使用ipdb.set_trace()
,您将获得完整的ipython会话及其所有便利。然而,bpdb.set_trace()
不给我一个bpython会话,它给了我标准的pdb
调试器。
是否有任何设置方法,以便我可以在bpython会话中进行调试?
我想用bpython解释器进行调试。 我的问题类似于“Is it possible to go into ipython from code?”,它询问了关于ipython。是否可以使用bpython作为完整的调试器?
如果您使用ipdb.set_trace()
,您将获得完整的ipython会话及其所有便利。然而,bpdb.set_trace()
不给我一个bpython会话,它给了我标准的pdb
调试器。
是否有任何设置方法,以便我可以在bpython会话中进行调试?
是的,使用this wrapper,您也可以通过将语句import bpdb
添加到您的代码来访问。添加bpdb.set_trace()
无论你想打破,并从pdb
解释进入“B”跳入bpython
会话一切从栈帧:
# The MIT License
#
# Copyright (c) 2008 Bob Farrell
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import pdb
import bpython
class BPdb(pdb.Pdb):
""" PDB with BPython support. """
def __init__(self):
pdb.Pdb.__init__(self)
self.rcLines = []
self.prompt = '(BPdb) '
self.intro = 'Use "B" to enter bpython, Ctrl-d to exit it.'
def postloop(self):
# We only want to show the intro message once.
self.intro = None
pdb.Pdb.postloop(self)
### cmd.Cmd commands
def do_Bpython(self, arg):
bpython.embed(self.curframe.f_locals, ['-i'])
def help_Bpython(self):
print "B(python)"
print
print ("Invoke the bpython interpreter for this stack frame. To exit "
"bpython and return to a standard pdb press Ctrl-d")
### shortcuts
do_B = do_Bpython
help_B = help_Bpython
你的问题似乎完全有效的给我!
嗨,感谢您指点我,但这只是'pdb'的一个包装。它包含在'bpdb'模块中。当我使用它时,它只是给了我'pdb'调试器(即没有突出显示,完成,文档等)。除非它在你的机器上做了不同的事情? – YXD 2012-04-02 10:16:46
@MrE这似乎是为'bpython'提供的程度,但是Amjith是绝对正确的。为了将'pdb'作为调试器来扩展,'pdb ++'是最好的选择。 :) – MrGomez 2012-04-02 18:46:41
进一步检查,也就是读取上面的代码,如果您键入“B”,则跳到'bpython'会话中,从'pdb'调试器会话中读取上面的代码。所以我将其标记为正确。 – YXD 2012-04-02 22:11:50
如果您正在寻找一个看起来更酷的调试程序,它可以执行完成和语法高亮显示,您可能需要查看pdb ++。 http://pypi.python.org/pypi/pdbpp/
它在更换PDB下降。所以你可以继续使用
import pdb; pdb.set_trace()
它会让你进入pdb ++提示符。
尝试它会花费你很多吗? – Marcin 2012-03-29 10:17:02
@Marcin我应该说明'bpdb.set_trace()'给了我标准的'pdb'调试器 – YXD 2012-03-29 10:26:47
所以,这是一个问题吗?这个问题是如何产生的? – Marcin 2012-03-29 11:23:37