Python handles globals badly.
ian.g.kelly at gmail.com
Wed Sep 9 07:08:24 CEST 2015
On Tue, Sep 8, 2015 at 9:27 PM, Steven D'Aprano <steve at 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])" 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
More information about the Python-list