[Zope] Building a list programmatically under DTML

Heiko Stoermer heiko@mig.net
Tue, 07 Sep 1999 11:28:19 +0200


Rik Hoekstra wrote:

> > -----Original Message-----
> > From: stoermer@migserv.augsburg.mig.net
> > [mailto:stoermer@migserv.augsburg.mig.net]On Behalf Of Heiko Stoermer
> > Sent: Tuesday, September 07, 1999 10:01 AM
> > To: Timothy Grant; Zope Mailing List
> > Subject: Re: [Zope] Building a list programmatically under DTML
> >
> >
> > Timothy Grant wrote:
> >
> > > Hi,
> > >
> > > I'm working on a project where I need to build a list programmatically
> > >
> > > I have tried a number of variations of the following without much
> > > success. Once the list has been built, I need to pass it on to the next
> > > page:
> > >
> > > <dtml-call "REQUEST.set('idx', 0)">
> > > <dtml-call "REQUEST.set('desc', [])">
> > > <dtml-call "REQUEST.set('desc_qty', [])">
> > >  .
> > > .
> > >  .
> > > <td>
> > >   <dtml-var expr="_[Category]">
> > >   <dtml-if "_[Category][0:2] <> 'No'">
> > >     <dtml-call "REQUEST.set('desc[&dtml-idx;]', _[Category])">
> > >     <dtml-call "REQUEST.set('desc_qty[&dtml-idx;]', qty)">
> > >     <dtml-call "REQUEST.set('idx', idx + 1)">
> > >   </dtml-if>
> > > </td>
> > >
> > > All help would be greatly appreciated!
> > >
> > >
> > >
> >
> > Hi Timothy,
> > first of all: I can't give you a solution...   :-(
> > But maybe I can give you a hint, because I had a similar problem the other
> > day.
> > Unlike PERL, python does not allow you to populate a list by indexing
> > slots that are not populated yet. So the following code:
> > >>>lst = []
> > >>>lst[10] = 'foo'
> > will give you the following error:
> > >>>IndexError: list assignment index out of range
> > But as I can see from your code above, that's exactly what you would like
> > to do, and I doubt that DTML-lists behave any different than python
> > lists...
> > Maybe you should switch to an External Method that gives you access to the
> > list object's "append()" method, which allows you to expand an existing
> > (empty) list.
> >
>
> Just a short reply. As far as I know you can use append in dtml as well. For
> example
>
> <dtml-call expr="REQUEST.set('somevar', [])">
> <dtml-call expr="somevar.append('somevalue')">
>
> Rik

even better !
:-)

Heiko


--
Heiko Stoermer
MIG Augsburg