[Zope] is it possible to add numerical comparison test to dtml-in statement ? statement ?

chas panda@skinnyhippo.com
Mon, 10 Jan 2000 08:13:20 +0800


>On Sun, Jan 09, 2000 at 02:31:49AM +0800, chas wrote:
>> When looping over ZClass instances in a dtml-in statement,
>> I have constantly wanted to add a numerical test condition
>> (eg. "where X > 12" where X is a property of the instance) 
>Yep, since <dtml in "foo"> evaluates foo as a Python expression, the
>following should be possible:
><dtml in "_.filter(objectValues(['MyClass'], lamba x: return x > 12)">
>
>filter(alist, func) returns a list of all items in alist for which func
>returns true. The lamba construct can be used to define a function on
>the fly, similar to LISP and other functional programming languages. 
>lamba x: return x > 12
>is the same as:
>def afunc(x): 
>	return x > 12

Aaah, very clever :)

Thanks indeed, Stephen, for this makes things *much* easier. 
I was aware of filter() function in python and often use it
but I'd never really understood the point of lambda until now.
And none of this would have occured to me to use within DTML 
like that. 

Thank you again, I'm going to be using this a lot and truly
appreciate the clear explanations.

chas