PEP 308: Application needs

Dan L. Pierson dan at control.com
Thu Feb 13 10:29:15 EST 2003


One need for this sort of conditional expression that doesn't seem to
have been addressed in the discussion so far is the number of
applications written in Python or using Python as an extension language
which permit Python expressions (only) in many contexts.

The relevant application I'm most familiar with is Zope, where both DTML
and Zope Page Templates (ZPT) allow Python expressions in something like
HTML (there is now an alternate implementation of Page Templates which
can be used outside of Zope). If this was only Zope's problem I would say
that there is no reason to change Python just for one application.  However
I believe that we will find the same expression-only restriction in a number
of other applications.  If that is the case then it is better to have one 
common way to express a conditional expression in all of these contexts
instead of a number of application-specific partial solutions such as the
'test' function in DTML and ZPT.

I find that I frequently need expressions such as

  "object and object.thing or default"

The worse case, which I have required, is:

  "object and object.useful() and object or default"

I'd really like a less ugly and confusing way to express this without
having to encapsulate it in a separate file equivalent.  Either of
the following would be better:

  "(if object and object.useful(): object else: default)"

  "object and object.useful() then object else default"

Personally, I prefer the former, but would vote for either.  If not for
this problem, which was first brought to my attention by Dieter Maurer on
the zope-dev list, I would be mildly opposed to any change.




More information about the Python-list mailing list