Recently I experienced an unexpected result while trying to render a tuple of two items in a diml-method.
I brought the code down to its essence.
In a dtml method I have the following code:
The sequence of tuples is prepared in a function:
def tupleTest(self):
"test with a list of tuples"
tuplelist=[('a',1),('a',2),('b',1),('b',2)]
return tuplelist
The result when viewing the diml method looks like:
[('a', 1), ('a', 2), ('b', 1), ('b', 2)]
1
2
1
2
The call to <dtml-var "tupleTest()"> correctly displays the list of tuples, but the dtml-in sequence only displays the second item of each tuple.
This happens only when the tuple consists of 2 items. When the number of items is higher, the tuples are correctly displayed, also in the dtml-in sequence.
> sequence-item, sequence-key
>
> Usually, sequence-item is the current object and sequence-key
> raises a TypeError exception. If, however, the current object
> happens to be a pair, i.e. a tuple with two elements, then
> sequence-key is the first and sequence-item the second element in
> the pair[34].
The [34] refers to a footnote with the content "I think, this is
a misfeature".
In the past I kept that chapter under my pillow and I still have a copy in my archive, so I should have known and it is not unlikely that I once knew...