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
Zope3-users mailing list

Reply via email to