[Zope-dev] Help with DTML-IN statement

Leonardo Rochael Almeida leo@hiper.com.br
13 Mar 2002 17:05:13 -0300


Hi Gary,

This question is more suited to zope@zope.org instead of
zope-dev@zope.org, and you should not send html e-mail to any of these
two lists, but since we are here...

On Wed, 2002-03-13 at 16:13, Gary Yee wrote:
> Hello,
> 
> I am very new to Zope/DTML and I am a little confused with the operation of the DTML-IN statement. Here is the snippet of code
>  
> <table border=1 width=100%>
> <dtml-in expr="( ((1), (1,2),(4,5,6),(7,8,9)) )">
>      <tr>
>              <td><dtml-var sequence-item></td> 
>       </tr>
> </dtml-in>
> </table>
> 
>  
> This code displays the contents 4 cells in a table and the output is
> 1
> 2
> (4,5,6)
> (7,8,9)
> 
> I am a litte confused because I thought it would display the contents of the list as
> (1)
> (1,2)
> (4,5,6)
> (7,8,9)
> 
> I believe this is related to something I read about tuples of ( key, value) will handled with sequence-key and sequence-item ????

That's exactly what's happening. It's a misfeature in my opinion, but it
makes it easy to iterate thru a dictionary .items() and a folder
.objectItems().

> I must be traversing the list incorrectly.....

No, you're not, the feature is wrong :-)

> can anyone give me an example of how to traverse this list of tuples
> correctly. 

The workaround is to make each tuple of your sequence the second
elemento of a 2-tuple, as in '((1, (1,)), (2, (1, 2)), (3, (4, 5, 6)),
(4, (4, 5, 6)))'

Kind of like that old joke were the paranoid statician would take a bomb
with himself to the plane because the odds of there being two bombs on a
plane were so low...

-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.