[Zope3-Users] Re: Fwd: Re: test() in TALES in Zope3

Paul Winkler pw_lists at slinkp.com
Wed Feb 1 14:57:58 EST 2006


On Wed, Feb 01, 2006 at 01:38:15PM -0600, Michael Dudzik wrote:
> But why not just use (bar,foo)[C] in all cases, regardless of the value
> of bar or foo?

Because it always evaluates both foo and bar, and sometimes you can't
afford that (e.g. if they are expensive expressions rather than
simple variables).

Prior to python 2.5, there is AFAIK no other always-works
short-circuiting one-line conditional expression but this:
(bool(C) and [foo] or [bar])[0]


Generally I only care about this in TALES expressions;
in python I prefer to use the extra couple of lines to
use "if" and "else".

-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope3-users mailing list