【发布时间】:2011-05-11 14:28:57
【问题描述】:
如果我有:
map = { 'stack':'overflow' }
try:
map['experts-exchange']
except: <--- What is the Exception type that's thrown here?
print( 'is not free' )
在网上找不到。 =(
【问题讨论】:
-
你在哪里看的? docs.python.org/library/stdtypes.html 的页面说“d[key] -- 返回 d 的项目,其中包含 key key。如果 key 不在地图中,则引发 KeyError。”
-
我基本上在 Bing 中输入了“Python 字典异常”并在前 3 个链接后放弃了。以为我可以在 SO 上得到更快的答案。 =p 但感谢您在此处提供参考链接。
-
您应该使用交互式控制台来查看这样的结果。
-
我认为这个问题还不错,因为当有人搜索它时,它会显示在搜索引擎上,而不必搜索它,对吧?
-
这有点讽刺,因为如果你搜索 Python 抛出的内容,如果你寻找一个不存在的键,这是谷歌的最高结果......谢谢你 ShaChris23
标签: python exception dictionary