[Python-ideas] Using "||" (doubled pipe) as the null coalescing operator?
Erik
python at lucidity.plus.com
Fri Sep 25 02:30:54 CEST 2015
Throwing this one out there in case it inspires someone to come up with
a better variation (or to get it explicitly rejected):
object.(<accessor> if <condition> else <expr>)
... where 'accessor' is anything normally allowed after 'object' ([],
(), attr) and 'condition' can omit the LHS of any conditional expression
(which is taken the associated object) or not (i.e., can be a complete
condition independent of the associated object):
foo = bar.((param0, param1) if not None else default())
foo = bar.([idx] if != sentinel else default())
And the perhaps more off-the-wall (as 'bar' is not involved in the
condition):
foo = bar.(attr if secrets.randint(0, 1023) & 1 else default())
E.
More information about the Python-ideas
mailing list