Proposal: function which simulates C ?: operator
Mel Wilson
mwilson at the-wire.com
Sun Jul 11 08:58:14 EDT 2004
In article <1388851004.20040711153354 at smtp.myrealbox.com>,
Adal Chiriliuc <me at spammers.com> wrote:
>I think a function similar to the one below should be added to the
>builtin module:
>
>def boolselect(condition, trueresult, falseresult):
> if condition:
> return trueresult
> else:
> return falseresult
>
>[ ... ]
>What do you think?
>
>PS: maybe a better name than boolselect could be found.
Some poeple might be disturbed by what it would do with
this_line = boolselect (dummy_flag, "Dummy line\n", infile.readline())
Side-effects are the main reason that a simple function
can't generally replace a full conditional ternary operator.
See google for the ternary operator debate, and see the other
discussion in clp right now.
Regards. Mel.
More information about the Python-list
mailing list