ipython 调试器:交互式 pdb 上的完整回溯?
我最近从 ipython0.10 切换到 ipython0.11。在 ipython0.11 中,当 python 调试器参与时(即使用 %pdb
),我只能看到完整回溯的一小部分,而在 ipython0.10 中我会看到完整回溯。据我所知,完整的回溯不能直接从 pdb 命令行访问 - 您可以使用“u”浏览它,但无法直接看到它。
那么,有什么方法可以显示完整的回溯吗?比如配置参数?
或者,更有用的是,有没有办法让 ipython 只显示捕获的异常,而不是显示在代码中捕获的异常?
编辑:示例:
In [1]: pdb
Automatic pdb calling has been turned ON
In [2]: 1/0
> <ipython-input-2-05c9758a9c21>(1)<module>()
-1 1/0
ipdb> q
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/Users/adam/<ipython-input-2-05c9758a9c21> in <module>()
----> 1 1/0
ZeroDivisionError: integer division or modulo by zero
我希望在 pdb 中看到 ZeroDivisionError before q
'。
I recently switched from ipython0.10 to ipython0.11. In ipython0.11, I only see a small snippet of the full traceback when the python debugger engages (i.e. using %pdb
), whereas in ipython0.10 I'd see the full traceback. As far as I can tell, the full traceback is not directly accessible from the pdb command line - you can navigate through it with 'u' but can't see it directly.
So, is there any way to show the full traceback? Such as a configuration parameter?
Or, even more usefully, is there any way to have ipython just show the Exception that was caught, rather than showing where in the code it was caught?
EDIT: Example:
In [1]: pdb
Automatic pdb calling has been turned ON
In [2]: 1/0
> <ipython-input-2-05c9758a9c21>(1)<module>()
-1 1/0
ipdb> q
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/Users/adam/<ipython-input-2-05c9758a9c21> in <module>()
----> 1 1/0
ZeroDivisionError: integer division or modulo by zero
I'd like to see the ZeroDivisionError before q
'ing out of the pdb.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
sys.excepthook
:来自
sys
模块文档:您还可以尝试将
--xmode
选项设置为Plain
从 IPython 参考:
以下是一些用法示例。请注意每个回溯的行数差异:
--xmode=Plain
:--xmode=Context
:< strong>
--xmode=Verbose
:并且在不指定 .py 文件的情况下:
--xmode=Plain
:--xmode=Context
:--xmode=Verbose
:使用 Python 调试器。
You could use
sys.excepthook
:From the
sys
module documentation:You can also try starting ipython with the
--xmode
option set toPlain
From IPython reference:
Here are some example usages. Notice the difference in lines for each traceback:
--xmode=Plain
:--xmode=Context
:--xmode=Verbose
:And without specifying a .py file:
--xmode=Plain
:--xmode=Context
:--xmode=Verbose
:Using the Python debugger.