PEP 308: some candidate uses cases from live code

Paul Rubin http
Tue Feb 11 19:23:12 EST 2003


Martin Maney <maney at pobox.com> writes:
> These are the uses of a simple if/else that seemed to me to be at least
> vaguely suitable for the proposed ternary operator; most of the if/else
> occurences rejected were over four lines or had very little in common
> between the if and the else code.  I don't believe I omitted any that
> weren't less good candidates than the ones below.

I think occurrences of
 
   x = foo     # set default value
   if cond:
      x = bar

should also count as potential places for a conditional expression,
even though no "else" is involved.  It's a shortcut for

   if cond: x = bar
   else: x = foo

and so instances of it should be included in your "database".




More information about the Python-list mailing list