2012-03-27 92 views
18

我想用bpython解释器进行调试。 我的问题类似于“Is it possible to go into ipython from code?”,它询问了关于ipython。是否可以使用bpython作为完整的调试器?

如果您使用ipdb.set_trace(),您将获得完整的ipython会话及其所有便利。然而,bpdb.set_trace()不给我一个bpython会话,它给了我标准的pdb调试器。

是否有任何设置方法,以便我可以在bpython会话中进行调试?

+0

尝试它会花费你很多吗? – Marcin 2012-03-29 10:17:02

+0

@Marcin我应该说明'bpdb.set_trace()'给了我标准的'pdb'调试器 – YXD 2012-03-29 10:26:47

+0

所以,这是一个问题吗?这个问题是如何产生的? – Marcin 2012-03-29 11:23:37

回答

23

是的,使用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 

你的问题似乎完全有效的给我!

+1

嗨,感谢您指点我,但这只是'pdb'的一个包装。它包含在'bpdb'模块中。当我使用它时,它只是给了我'pdb'调试器(即没有突出显示,完成,文档等)。除非它在你的机器上做了不同的事情? – YXD 2012-04-02 10:16:46

+0

@MrE这似乎是为'bpython'提供的程度,但是Amjith是绝对正确的。为了将'pdb'作为调试器来扩展,'pdb ++'是最好的选择。 :) – MrGomez 2012-04-02 18:46:41

+0

进一步检查,也就是读取上面的代码,如果您键入“B”,则跳到'bpython'会话中,从'pdb'调试器会话中读取上面的代码。所以我将其标记为正确。 – YXD 2012-04-02 22:11:50

10

如果您正在寻找一个看起来更酷的调试程序,它可以执行完成和语法高亮显示,您可能需要查看pdb ++。 http://pypi.python.org/pypi/pdbpp/

enter image description here

它在更换PDB下降。所以你可以继续使用

import pdb; pdb.set_trace() 

它会让你进入pdb ++提示符。

+2

嘿,这真的很好。不像bpython那么光滑(在交互模式下),但仍然是一次大而无痛的升级。 – YXD 2012-04-02 10:20:06

+1

我同意,完成并不像bpython那么棒。我喜欢粘贴功能,代码如上所示,并突出显示正在执行的当前行。 – Amjith 2012-04-02 17:39:46

相关问题