[Zope] Building a list programmatically under DTML
Heiko Stoermer
heiko@mig.net
Tue, 07 Sep 1999 10:00:47 +0200
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.
Hope this helps a little,
Heiko
--
Heiko Stoermer
MIG Augsburg