如何在iPython中正常显示异常?

时间:2016-01-11 17:25:01

标签: python ipython

我喜欢iPythons混合终端命令和Python的方式,但我不喜欢它显示异常的方式。它看起来像这样:

>>> import foo
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-34d390fb3acc> in <module>()
----> 1 import foo

ImportError: No module named foo

我宁愿看到正常的Python异常打印:

>>> import foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named foo

我在配置中搜索了这样的设置但找不到它。我该怎么办?

1 个答案:

答案 0 :(得分:6)

xmode设为plain

In [8]: %xmode plain
Exception reporting mode: Plain

In [9]: import foo
Traceback (most recent call last):
  File "<ipython-input-9-34d390fb3acc>", line 1, in <module>
    import foo
ImportError: No module named 'foo'

或使用相应的配置文件条目:

c.TerminalInteractiveShell.xmode = 'Plain'