[ZPT] If/else?

Guido van Rossum guido@digicool.com
Thu, 10 May 2001 08:39:33 -0500


> From: richard@bizarsoftware.com.au
> 
> Evan Simpson wrote:
> > It's all at
> > http://dev.zope.org/Wikis/DevSite/Projects/ZPT/EliminatePathModifiers
> 
> This looks really good!
> 
> The definition of the '|' operator is missing a statement about the
> correctness of the path resolution. Guido's email stated '"x | y | z" will
> evaluate to the path x if it is defined and non-empty...' but the wiki page
> only talks about evaluating to a 'true value'.

I'll leave it to Evan to fix the Wiki -- I'm sure he *meant* "It will
try to evaluate each path, from left to right, until it finds one that
evaluates without errors and has a true value."

> Here's a thought too...
> 
> <div tal:condition="python:exists('a/b/c')"
>      tal:replace="a/b/c/d" />
> 
> ... and
> 
> <div tal:replace="a/b/c/d | nothing" />

You mean default rather than nothing.

> ... apear to achieve the same result. Could this spell the death of
> tal:condition?

It spells the death of abuse of tal:condition to test for existence or
truth of the replacement variable only. :-)

> Also, with the tag...
> 
> <div tal:replace="python:path('a/b') + 1" />
> 
> ... the wiki page says that path() will return an error object if the path
> doesn't resolve. What will the result of "<error object> + 1" be?

An error.  *Use* of the error object outside some very limited
contexts will raise an exception.

--Guido van Rossum (home page: http://www.python.org/~guido/)