Python ConfigParser: Checking for option existence

╄→尐↘猪︶ㄣ 提交于 2019-12-03 22:08:10

The choice between try/except and if-condition is a fuzzy line.

  1. If you expect the exception to be quite rare, use try/except as it more closely models thinking
  2. Conversely, "expected" exceptions like a configuration item missing, are part of the normal flow of control and the code should reflect that.

There is no clearly superior choice, but it sounds like you've got a case of (2) so I'd opt for if/then. This completely ignores aspects of Easier to ask Forgiveness Than Permission and the relative efficiencies of the structures.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!