[Zope-dev] [] vs () in dtml-in: is this a bug ?

Steve Alexander steve@cat-box.net
Sun, 22 Apr 2001 13:16:57 +0100


Stefane Fermigier wrote:

> Hi,
> 
> please try this as a DTML Method:
> 
> <dtml-let l="[[1, 2], [3, 4]]">
> <dtml-in l>
>   <dtml-var "_['sequence-item']"><br>
> </dtml-in>
> </dtml-let>
> 	 
> <dtml-let l="[(1, 2), (3, 4)]">
> <dtml-in l>
>   <dtml-var "_['sequence-item']"><br>
> </dtml-in>
> </dtml-let>
> 
> Why should the two results differ ?


This is a designed-in feature of dtml-in.

When you call an items() method on a dictionary-like object, you get 
back a list of two-tuples: [(key1,value1), (key2,value2, ...]

It is often nice to iterate through such a list in dtml, so, dtml-in 
detects that the next item in the iteration is a two-tuple, and puts the 
elements of the tuple in sequence-key and sequence-item.

  If you look throughthe zope-dev list archives, you'll find a number of 
arguments on each side as to whether this is a bug or a feature.

--
Steve Alexander
Software Engineer
Cat-Box limited