KeyError不格式化错误消息

时间:2018-05-22 00:47:01

标签: python python-3.x

引发KeyError不会格式化字符串而其他错误的原因是什么? (注意嵌入的\n vs下面示例中的新行)

In [1]: raise KeyError("Does not \n format")
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-2a34667e842b> in <module>()
----> 1 raise KeyError("Does not \n format")

KeyError: 'Does not \n format'

ValueError

In [2]: raise ValueError("Does \n format")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-3f8ba28869e2> in <module>()
----> 1 raise ValueError("Does \n format")

ValueError: Does 
 format

IndexError

 In [3]: raise IndexError("Does \n format")
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-4-2db4e87594fd> in <module>()
----> 1 raise IndexError("Does \n format")

IndexError: Does 
 format

0 个答案:

没有答案