[Zope] Testing multiple values for existance - still

Phil Harris phil.harris@zope.co.uk
25 Sep 2001 10:24:48 -0400


Oliver,

You are missing the distinction between:

<dtml-if foo>

and 

<dtml-if "foo and bar">

You're also missing some of the maddening Zope 'Magic'.

The first statement tests first for existence, and only then for value.
The second assumes existence and only tests for value.

In your case I think you were testing for the esitence of a method, not
of a variable, am I right?  If foo doesn't exist then the first test
returns false because foo is not in the currrent namespace, the second
though drops into Python rules and has none of the Zope 'magic' applied.

I hope this goes someway to explain what you asked, of course if you'd
said explicitly that you were testing for the existence of methods in
the current folder, then this could be made a bit simpler.

hth

Phil
phil.harris@zope.co.uk

On 25 Sep 2001 10:10:28 +0200, Oliver Sturm wrote:
> On 24.09.2001 21:26:28 +0200 Dieter Maurer <dieter@handshake.de> wrote:
> 
> > Apparently, you ignored my reply.....
> > 
> >      <dtml-if "(_.has_key('foo') and foo) or (_.has_key('bar') and bar)">
> 
> Sorry, it seems I did. And that's sad, because it's the only one that really
> works out of the box. One question, though: After fiddling around a bit with
> that line (still trying to understand things better :-), it seems that 
> 
> <dtml-if "(_.has_key('foo')) or (_.has_key('bar'))">
> 
> works the same. In what situation would there be a key in the global
> namespace (that's the _, isn't it?), but the name is still not defined?
> 
> The whole thing still has one great question for me:
> 
> - How exactly is the expression "foo" defined? I mean, in C, the expression 
>   "foo" is defined to be the same as "foo != 0", and that's true in all 
>   circumstances. I can use "foo && bar" as a substitute for "(foo != 0) && 
>   (bar != 0)". I still fail to see the consistency in the Python 
>   expressions, because <dtml-if "foo and bar"> does not do the same thing as 
>   <dtml-if foo><dtml-if bar>, at least not if foo and bar are not defined.
> 
> Thanks for your help!
> 
> Oliver
> 
> -- 
> Oliver Sturm / <sturm@oliver-sturm.de>
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )