I'm trying to use a choose statement inside a loop, I need to populate a table in this way:
<tr py:for="i in range(0,25)">
<py:choose my_list[i]='0'>
<py:when my_list[i]='0'><td>NOT OK</td></py:when>
<py:otherwise><td>OK</td></py:otherwise>
</py:choose>
...
...
</tr>
I have an error on the line <py:choose...>:
TemplateSyntaxError: not well-formed (invalid token): line...
But I cannot understand well how to use the choose statement! If I think as C-like (and it seem to me more logical) I need to write only:
<tr py:for="i in range(0,25)">
<py:choose my_list[i]>
<py:when my_list[i]='0'><td>NOT OK</td></py:when>
<py:otherwise><td>OK</td></py:otherwise>
</py:choose>
...
...
</tr>
Can you help me?
Oh, my_list is a list of string. Then, if the string is 0 then for me is NOT OK, everything else is OK.
Within the
py:choose, you're not access theIthitem of my_list. Instead,iis set equal to theintfrom range. I assume this is a contrived example, and you're trying to access theIthvalue ofmy_list. In this case, you should just iterate overmy_listinstead of usingrangeat all.Here's an example using your current methodolgies. The error is within
py:chooseitself:However, you should probably change
list_of_intstomy_list, and iterate over it directly. Or even better, if you must know the index of each item from withinmy_list, useenumerate:Of course, these examples were made to run from a python interpreter. You can modify this to work with your setup easily.
HTH