我正在写一个脚本,我需要尝试在一封电子邮件上应用几种解析方法。因此,如果第一个成功了,就没有必要尝试其他的。到目前为止,我只有2个解析方法,但我可能会添加更多。如果可能的话,我想复制一些类似switch case的东西(在2.7中不存在)。有比我做的更好的吗?你知道吗
try:
found['PhishMe_Informations']=self.parse_phishme(message)
except MalformedPhishMeMailError as e:
self.log.error(e[0])
found['PhishMe_Informations']=e[1]
found['PhishMe_Informations']['Malformed']=True
except Exception:
try:
found['Journaling_Informations']=self.parse_journaling(message)
except MalformedRecordMessageError as e:
self.log.error(e)
except Exception:
pass
您可以尝试在声明模式中构建函数和可能异常的层次结构树,然后编写处理它的代码。在您的用例中,它可以是:
处理该树的方法可以是:
相关问题 更多 >
编程相关推荐