[Zope-dev] Confused about manipulating nested lists in DTML
Martijn Pieters
mj@antraciet.nl
Mon, 15 Mar 1999 14:59:56 +0100
At 14:33 15/03/99 , skip@mojam.com wrote:
>
>I have a list of lists:
>
> [['Washington', 'state'], ['Washington', 'state', 'Auburn'], ...]
>
>The first element has length two, the rest length three. If I pass that to
>a DocumentTemplate instance as a parameter named "data" and manipulate it
>thus:
>
> <!--#var "len(_['data'])"-->
> <!--#var data-->
> <!--#in data-->
> <!--#var "len(_['sequence-item'])"--> <!--#var sequence-item-->
> <!--#if "len(_['sequence-item']) == 2"-->
> <p><!--#var "_['sequence-item'][0]"-->
> <!--#in sequence-item-->
> <!--#var sequence-item--><br>
> <!--#/in-->
> <!--#/if-->
> <!--#/in-->
>
>I get the following output:
<<SNIP>>
>*What* objects have lengths of 9 and 18? The outer list is length 33. The
>inner lists are all length 2 or 3. Obviously I screwed up and misused
>len(), but how?
>
The function len() is not Python's len(), but Zope's len(), and it only
returns lengths on strings.... just count the number of characters in
"_['data']" and "len(_['sequence-item'])".
You *should* use _.len():
<!--#var "_.len(data)"-->
<!--#var data-->
<!--#in data-->
<!--#var "_.len(_['sequence-item'])"--> <!--#var sequence-item-->
<!--#if "_.len(_['sequence-item']) == 2"-->
<p><!--#var "_['sequence-item'][0]"-->
<!--#in sequence-item-->
<!--#var sequence-item--><br>
<!--#/in-->
<!--#/if-->
<!--#/in-->
--
M.J. Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-6254545 Fax: +31-35-6254555
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------