[Zope] ZCatalog/python script question
Dieter Maurer
dieter@handshake.de
Wed, 19 Sep 2001 18:55:02 +0200 (CEST)
ksmith@99hats.com writes:
> Is something like this possible in python scripts?
>
> <dtml-in Catalog size=5>
> <dtml-var title>
> </dtml-in>
Not sure, what you want to achieve in detail....
The above DTML code generates a string containing of up to
5 titles.
In my answer below, I expect you do not want to generate
a string but a list.
l=[]
r= context.Catalog()
n= min(5,len(r))
for i in range(n):
l.append(r[i].title)
return l
"dtml-in" tries hard not to call "len(r)" by using:
try: r[4]
except: n= len(r)
else: n= 5
But I think, this is not relevant for catalog searches
(use it, if I should be wrong).
Dieter