[triangle-zpug] Last evening's meeting

Geoff Davis geoff at geoffdavis.net
Thu May 27 21:51:18 CEST 2004


> 5) How do you do an "else" in ZPT? :)

A few tricks:

<tal:block tal:define="foo python:test(is_this_expression_true,
expression_if_true, expression_if_false)">

is roughly equivalent to 

t = expression_if_true
f = expression_if_false

if is_this_expression_true:
	foo = t
else:
	foo = f

The syntax, while convenient, has the downside of evaluating both
expression_if_true and expression_if_false.

<tal:block tal:define="foo python:is_this_expression_true and
expression_if_true or expression_if_false">

is roughly equivalent to 

if is_this_expression_true:
	foo = expression_if_true
else:
	foo = expression_if_false

AS LONG AS expression_if_true IS NOT 0 OR '' OR False

(I make no guarantees on this second option -- it's just a quick from-memory
brain dump)

Sorry I missed the meeting!

Geoff




More information about the triangle-zpug mailing list