[Zope] Testing multiple values for existance - still

Dieter Maurer dieter@handshake.de
Tue, 25 Sep 2001 22:41:31 +0200 (CEST)


Oliver Sturm writes:
 > ....
 > >      <dtml-if "(_.has_key('foo') and foo) or (_.has_key('bar') and bar)">
 > versus
 > <dtml-if "(_.has_key('foo')) or (_.has_key('bar'))">
 > ... difference?

In the first case, you test both existence and value,
in the second case only existence.

In general:

   <dtml-if XXX>

is equivalent to

   <dtml-if "_.has_key('XXX') and XXX">

More details:

  <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>

 > - How exactly is the expression "foo" defined?
The expression "foo" is defined as "foo"....

But, when you use it with "dtml-if" or in another boolean context,
then it is checked whether it has a Python true value.
Everything, that is not a Python false value, is a Python true value.
Python false values are e.g. the integer 0, the empty string, an
empty sequence, and object "o" with "len(o) == 0", an
object "o" with "o.__non_zero__() = 0".
More details: Python language reference....



Dieter