How do I access an item in a list from dtml?
I've read everything three times, searched the egroups index, and can't find the answer to this simple question. Unfortunately it seems to be a namespace question and it's hard to phrase the question in a searchable way. If I have passed a variable of type list to a method - in this case, it's a mailhost method - how do I access an item of that list? Example: I'm passing the following: parms=['item1','item2','item3'] and the Pythonic way to access an item of this list would be simply parms[0] or parms[1] etc. But when I try <dtml-var parms[0]> I get a KeyError for parms[0]. Doing <dtml-var parms> shows the list all right. I can interate over the list with <dtml-in parms> all right also. But I need to get particular items of the list and cannot figure out how to do that. I tried <dtml-var "_getitem(parms[0],0)"> as hinted at by a howto, but that just gives me a 'slice error; I can't find the magic '_.'?!" set of punctuation marks that will let me simply access list items by index number!
The code below allows you to get at each item in a list one at a time. Hope this helps. DR <!--#in tabularHeaders--> <!--#call "REQUEST.set('headerVars',_['sequence-item'])"--> <Th><B><!--#var expr="headerVars"--></B></th> <!--#/in tabularHeaders-->
On Wed, 13 Oct 1999, Gustin Kiffney wrote:
Example: I'm passing the following: parms=['item1','item2','item3'] and the Pythonic way to access an item of this list would be simply parms[0] or parms[1] etc.
But when I try <dtml-var parms[0]> I get a KeyError for parms[0]. Doing <dtml-var parms> shows the list all right. I can interate over the list with <dtml-in parms> all right also. But I need to get particular items of the list and cannot figure out how to do that.
Try: <dtml-var "parms[0]"> <dtml-var expr="parms[0]"> is actually the correct expression but for convinience <dtml-var ...> will call the argument if it is callable. Use quotes whenever you need to suplly arguments etc. Pavlos
participants (3)
-
Dan Rusch -
Gustin Kiffney -
Pavlos Christoforou