为什么这个TypeError
没有被异常捕获?
>>> op=None
>>> try:
... val = op['one']
... except KeyError, TypeError:
... val = "one"
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: 'NoneType' object has no attribute '__getitem__'
>>>
最佳答案
您必须将异常(exception)列表括在括号中:
except (KeyError, TypeError):
# ^ ^
val = "one"
关于python - TypeError 异常未被捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46939163/