Re: [Zope] Testing multiple values for existance - still
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
On 25.09.2001 22:41:31 +0200 Dieter Maurer <dieter@handshake.de> wrote:
- How exactly is the expression "foo" defined? The expression "foo" is defined as "foo"....
I was thinking of "foo" as a Zope expression like in <dtml-if foo>. Like I wrote in the other thread, there must be some internal method that Zope uses to do that existence and value check. Why can't I use that from the Python expression? (Yes, I know that now, I can do the same thing, only I thought it was a little more intuitive.) Oliver -- Oliver Sturm / <sturm@oliver-sturm.de>
Oliver Sturm writes:
On 25.09.2001 22:41:31 +0200 Dieter Maurer <dieter@handshake.de> wrote:
- How exactly is the expression "foo" defined? The expression "foo" is defined as "foo"....
I was thinking of "foo" as a Zope expression like in <dtml-if foo>. Like I wrote in the other thread, there must be some internal method that Zope uses to do that existence and value check. Why can't I use that from the Python expression? (Yes, I know that now, I can do the same thing, only I thought it was a little more intuitive.)
Again, you stopped reading too early! The section following the one quoted above explained how "foo" is interpreted in a boolean context (such as the "dtml-if"). It is the same way as in Python with the exception that "dtml-if" considers a missing name as false while Python considers a missing name as an exception... Please read my replies carefully! It takes time to prepare them and it is unfriendly to ignore essential parts of them and therefore follow-up with an additional question. I may use the kill-file facility of my newsreader to protect myself.... Dieter
On 26.09.2001 19:54:37 +0200 Dieter Maurer <dieter@handshake.de> wrote:
- How exactly is the expression "foo" defined? The expression "foo" is defined as "foo"....
I was thinking of "foo" as a Zope expression like in <dtml-if foo>. Like I > wrote in the other thread, there must be some internal method that Zope uses > to do that existence and value check. Why can't I use that from the Python > expression? (Yes, I know that now, I can do the same thing, only I thought > it was a little more intuitive.)
Again, you stopped reading too early!
No, I didn't.
The section following the one quoted above explained how "foo" is interpreted in a boolean context (such as the "dtml-if").
The section you are referring to details how "foo" is interpreted in a boolean context in the Python language. I was asking how the expression "foo" is interpreted in <dtml-if foo> (not <dtml-if "foo">), that is, in a Zope context. Obviously, there's a difference, otherwise <dtml-if foo> and <dtml-if "foo"> would be the same and <dtml-if "foo and bar"> would be the same as <dtml-if foo><dtml-if bar>, which is not the case.
It is the same way as in Python with the exception that "dtml-if" considers a missing name as false while Python considers a missing name as an exception...
And the question was how do I write a Python expression that works on the foo thing just the same way Zope (the dtml-if) does. You answered that already early on, thanks for that, and I was only commenting that I was expecting to find that functionality, which is very integral to Zope, readily available for my use. Something like the script check_for_any that Paul Winkler kindly provided in the other thread would belong in some global library for everyone to use instead of reinvent the wheel all the time. I'm absolutely sure there's such a function somewhere in Zope source, I was only wondering why I have to write complex expressions instead of just using it.
Please read my replies carefully!
It takes time to prepare them and it is unfriendly to ignore essential parts of them and therefore follow-up with an additional question.
I may use the kill-file facility of my newsreader to protect myself....
Dear lord. Oliver -- Oliver Sturm / <sturm@oliver-sturm.de>
Oliver Sturm writes:
The section following the one quoted above explained how "foo" is interpreted in a boolean context (such as the "dtml-if").
The section you are referring to details how "foo" is interpreted in a boolean context in the Python language. I was asking how the expression "foo" is interpreted in <dtml-if foo> (not <dtml-if "foo">), I had also this answered already!
<dtml-if XXX> is equivalent to <dtml-if expr="_.has_key('XXX') and XXX"> You find this (and lots of other facts) in <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> Dieter
participants (2)
-
Dieter Maurer -
Oliver Sturm