PEP 308: A PEP Writer's Experience - PRO

Dave Brueck dave at pythonapocrypha.com
Sat Feb 8 20:25:15 CET 2003


On Sat, 8 Feb 2003, Aahz wrote:

> 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.

No, Michael's example is valid. What if the 'undefined' output should be
'[Not yet entered]' or something? You got off easy just because his
example happened to choose for a default the string representation of the
None object.

-Dave





More information about the Python-list mailing list