【发布时间】:2018-01-05 23:26:19
【问题描述】:
我的字典包含键(可能重复也可能不重复)和值(都是唯一的)。当我的键值对不起作用时,我收到异常错误。当我遇到异常时,我想移动到下一个匹配键,并尝试它的值。如果它们都不起作用,请到达“finally”异常处理程序并继续下一个键。
以下是列出的某种逻辑,除了我当前的逻辑仅在我想在达到“最终”之前用尽所有关键选项时尝试另一种关键可能性。
for currentFile, originalFile in filepath_dictionary.items():
try:
relocateSource(currentFile, originalFile)
except:
# (Some logic which tries the next key, value pair in which the key matches the current key
finally:
print 'Could not relocate file: ' + currentFile
【问题讨论】:
-
您的密钥不会重复。
标签: python python-2.7 dictionary exception