[Zope] re: Length of results set

Dieter Maurer dieter@handshake.de
Thu, 16 Jan 2003 22:52:29 +0100


Ken wrote at 2003-1-16 17:39 +0100:
 > Maybe I'd better re-phrase my question. I think it will be easy for many of you, maybe even me.. I had too much coffee last night. 
 > 
 > How do you get the length of results for a <dtml-if> inside a <dtml-in> ?
You do *NOT* do this in DTML!

In Python, you simple count all positive hits in a loop:

   i= 0
   for o in context.objectValues():
     if ...: i+= 1
   return i

or you use "list comprehension" (see Python documentation) and "len"

   return len([o for o in context.objectValues() if ...])

You see, how easy it is in Python?


Dieter