On Tue, Sep 8, 2015 at 9:27 PM, Steven D'Aprano <st...@pearwood.info> wrote:
> Using if...then statement is too heavyweight, and cannot be used in an
> expression. Using "flag and true_value or false_value" is buggy -- it fails
> if true_value is itself false. Refactoring it to a function uses eager
> rather than lazy evaluation. So there was no existing alternative to a
> ternary if expression that worked correctly.

I used to see "(flag and [true_value] or [false_value])[0]" fairly
often, which solves the bugginess problem by ensuring that the second
term can't be false. Not that I would recommend it over an actual
conditional expression.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to