In particular, this is not idiomatic python:
if "key" in dict_:
value += dict_["key"]
But this is: try:
value += dict_["key"]
except KeyError:
pass
I too hate using the exception handling in this way, and if you aren't careful, you end up papering over other unexpected exceptions in your code, so you have to be (A) very specific in the exception you catch, and (B) keep it in as small a portion of code as possible.I just think it makes for clumsy code - which of the two look better:
try:
value = dict_["key"]
except KeyError:
pass
else:
do_something(value)
OR if "key" in dict_:
do_something(dict["key"])
But it might just be me.