For review: PEP 308 - If-then-else expression

Richard Jones rjones at ekit-inc.com
Sat Feb 8 04:16:12 CET 2003


On Sat, 8 Feb 2003 2:01 pm, Andrew Dalke wrote:
> David Gausebeck:
> > The simple example I used in a previous thread is:
> >
> >    if is_html:
> >       extension = "html"
> >    else:
> >       extension = "txt"
> >    print "Processed %s.%s." % (filename, extension)
> >
> > This could currently also be implemented as
> >
> >    print "Processed %s.%s." % (filename, is_html and "html" or "txt")
> >
> > Per the PEP, it would be
> >
> >    print "Processed %s.%s." % (filename, "html" if is_html else "txt")
>
> This could also currently be written as
>
>      print "Processed %s.%s." % (filename, ["txt", "html"][is_html])

And I'd argue that anything more complex that this belongs in a statment, with 
blocks and all that jazz.


    Richard






More information about the Python-list mailing list