My .02 on PEP308 + an extra question.

Roman Suzi rnd at onego.ru
Mon Feb 10 12:59:43 EST 2003


On Mon, 10 Feb 2003, Adonis wrote:

>How about something like:
>
>x = iif(cond, true, false)
>
>BUT, why mingle with all this when anyone can simply make it?
>
>>>> def iif(cond, ctrue, cfalse):
>...     if cond: return ctrue
>...     else: return cfalse
>...
>>>> y = 7
>>>> x = iif(y==1, True, False)
>>>> x
>False
>>>> y = 1
>>>> x = iif(y==1, True, False)
>>>> x
>True
>>>>
>
>or am I getting the concept all wrong?

The problem is that inline if must not evaluate it's 2nd and 3d
arguments. Because the condition is often used to check
applicability of True part, like in:

if x:
  return x.method()
else:
  return None


Sincerely yours, Roman Suzi
-- 
rnd at onego.ru =\= My AI powered by Linux RedHat 7.3






More information about the Python-list mailing list