Python handles globals badly.

Ian Kelly ian.g.kelly at
Wed Sep 9 07:08:24 CEST 2015

On Tue, Sep 8, 2015 at 9:27 PM, Steven D'Aprano <steve at> 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.

More information about the Python-list mailing list