On 19 February 2014 13:30, Chris Angelico <rosuav@gmail.com> wrote:
On Wed, Feb 19, 2014 at 11:57 PM, Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote:
I don't know how common a pattern it is in other people's code but something like:
header = { 'param1': foo, 'param2': bar, ... }
try: header['paramN'] = load_from_file(baz, spam) except OSError: header['paramN'] = ''
That looks awesome! Do you have actual production code that looks like that, and if so, can I have a squiz at it? Because that's a strong use-case right there.
I can't really find anything like that right now. I was just thinking that there are basically two situations where I like to use ternary if/else: as part of a larger expression/display or in a comprehension/generator expression. This proposal is similar but it's hard to find the cases that would be simplified by it as they will probably be written in a very different way right now. Oscar