Martin McBride
1 min readJul 31, 2020

--

Is try-except unpythonic? Surely duck typing (which is pretty much as pythonic as it gets) relies on catching exceptions?

Using get with a default is great if you need to handle missing keys by substituting a default value, which you sometimes do.

But in other cases, looking up a missing key would indicate a serious error condition, which is exactly what exceptions are for. So you should use [] and try-except.

Square brackets are not a "mistake".

--

--