On 2/21/2014 5:06 PM, Jan Kaliszewski wrote:
Or even (still being my favorite):

    msg = seq[i] except (IndexError: "nothing")

This syntax actually has a benefit: the parenthesized syntax after except could become a list, to allow handling different exceptions from the tried expression with different results:

msg = seq[dictionary[i]] except (IndexError: "nothing", KeyError: "serious problems")

And still allows nesting:

msg = seq[i] except (IndexError: dictionary[i] except (KeyError: "no fallback data for %s" % i))