PEP 308: A PEP Writer's Experience - PRO

Aahz aahz at pythoncraft.com
Sat Feb 8 12:10:36 EST 2003


In article <mailman.1044720530.25177.python-list at python.org>,
Michael Chermside  <mcherm at mcherm.com> wrote:
>
>If a ternary expression is available, then things can be done in
>expressions which would be impossible without it. lambda is the
>example most often given, but I think a different example is
>more compelling. Suppose you want to write a line of logging
>into your program:
>
>       print "x = " + x.getDisplayString()
>
>but you have to allow for the fact that x might be None. With
>a ternary expression, you can write this:
>
>       print "x = " + x.getDisplayString() if x else "None"

Why not

    print 'x =', x.getDisplayString()

or

    print 'x = ' + str(x.getDisplayString())

The point is that many of the supposed uses for ternary do have simple,
effective workarounds.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Register for PyCon now!  http://www.python.org/pycon/reg.html




More information about the Python-list mailing list