本文介绍了ipython调试器:交互式pdb上的完全回溯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我最近从ipython0.10切换到ipython0.11。在ipython0.11中,我只看到python调试器参与时的完整回溯的小片段(即使用%pdb ),而在ipython0.10中,我会看到完全追溯。据我所知,pdb命令行无法直接访问完整的回溯 - 您可以使用'u'导航它,但无法直接看到它。 或者,更有用的是,有没有办法让ipython只显示被捕获的异常,而不是显示代码中的位置被抓了? 编辑:示例: 在[1]中:pdb 自动pdb呼叫已开启 在[2]中:1/0 > < ipython-input-2-05c9758a9c21>(1)< module>() -1 1/0 ipdb> q --------------------------------------------- ------------------------------ ZeroDivisionError Traceback(最近一次调用最后一次) / Users / adam /< IPython的输入-2-05c9758a9c21> in< module>() ----> 1 1 $ ZeroDivisionError:整数除法或模数为零 I我希望在 q 之前看到ZeroDivisionError 从pdb中出来。解决方案 您可以使用 sys.excepthook : import sys def exc_hook(类型,值,追溯):打印类型 sys.excepthook = exc_hook 来自 sys 模块文档: 您也可以尝试启动ipython,并将 - xmode 选项设置为 Plain 来自 IPython参考:这里是一些示例用法。请注意每个回溯的行数差异: - xmode = Plain : [19:55 jon @ hozbox~ / SO / python] $ ipython --xmode = Plain ipython-debugger-full- traceback-on-interactive-pdb.py ------------------------------------- ----------------------- Traceback(最近一次调用最后一次):文件ipython-debugger-full-traceback-on -interactive-pdb.py,第2行,< module> 1/0 ZeroDivisionError:整数除法或模数为零 - xmode =上下文 : [19 :55 jon @ hozbox~ / SO / python] $ ipython --xmode =上下文ipython-debugger-full-traceback-on-interactive-pdb.py ------------- -------------------------------------------------- ------------ ZeroDivisionError Traceback(最近一次调用最后一次) / home / jon / SO / python / ipython-debugger-full-traceback-on -interactive-pdb.py in< module>() 1 ----> 2#!/ usr / bin / python 3 1/0 4 5 ZeroDivisionError:整数除法或模数为零 - xmode =详细 : [19:54 jon @ hozbox~ / SO / python] $ ipython --xmode =详细ipython-debugger-full-traceback- on-interactive-pdb.py --------------------------------------- ------------------------------------ ZeroDivisionError Traceback(最近一次调用最后一次) /home/jon/SO/python/ipython-debugger-full-traceback-on-interactive-pdb.py in< module>() 1 ---- > 2#!/ usr / bin / python 3 1/0 4 5 ZeroDivisionError:整数除法或模数为零 并且未指定.py文件: - xmode =普通 : [19:55 jon @hozbox~ / SO / python] $ ipython --xmode = Plain 在[1]中:1/0 --------------- --------------------------------------------- Traceback (最近的呼叫最后一次):文件< ipython console>,第1行,< module> ZeroDivisionError:整数除法或模数为零 --xmode =上下文 : [20:03 jon @ hozbox~ / SO / python] $ ipython --xmode =上下文 在[1]中:1/0 ------------------- -------------------------------------------------- ------ ZeroDivisionError Traceback(最近一次调用最后一次) / home / jon / SO / python /< ipython console> in< module>() ZeroDivisionError:整数除法或模数为零 - xmode =详细 : [20:01 jon @ hozbox~ / SO / python] $ ipython --xmode =详细 在[1]中:1/0 ---- -------------------------------------------------- --------------------- ZeroDivisionError Traceback(最近一次调用最后一次) / home / jon / SO / python / < ipython console> in< module>() ZeroDivisionError:整数除法或模数为零 使用Python调试器。 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]: pdbAutomatic pdb calling has been turned ONIn [2]: 1/0> <ipython-input-2-05c9758a9c21>(1)<module>() -1 1/0ipdb> q---------------------------------------------------------------------------ZeroDivisionError Traceback (most recent call last)/Users/adam/<ipython-input-2-05c9758a9c21> in <module>()----> 1 1/0ZeroDivisionError: integer division or modulo by zeroI'd like to see the ZeroDivisionError before q'ing out of the pdb. 解决方案 You could use sys.excepthook:import sysdef exc_hook(type, value, traceback): print typesys.excepthook = exc_hookFrom the sys module documentation:You can also try starting ipython with the --xmode option set to PlainFrom IPython reference:Here are some example usages. Notice the difference in lines for each traceback:--xmode=Plain:[ 19:55 jon@hozbox ~/SO/python ]$ ipython --xmode=Plain ipython-debugger-full-traceback-on-interactive-pdb.py------------------------------------------------------------Traceback (most recent call last): File "ipython-debugger-full-traceback-on-interactive-pdb.py", line 2, in <module> 1 / 0ZeroDivisionError: integer division or modulo by zero--xmode=Context:[ 19:55 jon@hozbox ~/SO/python ]$ ipython --xmode=Context ipython-debugger-full-traceback-on-interactive-pdb.py---------------------------------------------------------------------------ZeroDivisionError Traceback (most recent call last)/home/jon/SO/python/ipython-debugger-full-traceback-on-interactive-pdb.py in <module>() 1----> 2 #!/usr/bin/python 3 1 / 0 4 5ZeroDivisionError: integer division or modulo by zero--xmode=Verbose:[ 19:54 jon@hozbox ~/SO/python ]$ ipython --xmode=Verbose ipython-debugger-full-traceback-on-interactive-pdb.py---------------------------------------------------------------------------ZeroDivisionError Traceback (most recent call last)/home/jon/SO/python/ipython-debugger-full-traceback-on-interactive-pdb.py in <module>() 1----> 2 #!/usr/bin/python 3 1 / 0 4 5ZeroDivisionError: integer division or modulo by zeroAnd without specifying a .py file:--xmode=Plain:[ 19:55 jon@hozbox ~/SO/python ]$ ipython --xmode=PlainIn [1]: 1 / 0------------------------------------------------------------Traceback (most recent call last): File "<ipython console>", line 1, in <module>ZeroDivisionError: integer division or modulo by zero--xmode=Context:[ 20:03 jon@hozbox ~/SO/python ]$ ipython --xmode=ContextIn [1]: 1 / 0---------------------------------------------------------------------------ZeroDivisionError Traceback (most recent call last)/home/jon/SO/python/<ipython console> in <module>()ZeroDivisionError: integer division or modulo by zero--xmode=Verbose:[ 20:01 jon@hozbox ~/SO/python ]$ ipython --xmode=VerboseIn [1]: 1 / 0---------------------------------------------------------------------------ZeroDivisionError Traceback (most recent call last)/home/jon/SO/python/<ipython console> in <module>()ZeroDivisionError: integer division or modulo by zeroUsing the Python debugger. 这篇关于ipython调试器:交互式pdb上的完全回溯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 06:14