[英]Python Mako check loop iteration in IF
it seems so simple yet I can't seem to check if the inner loop is at the 7th iteration看起来很简单,但我似乎无法检查内部循环是否处于第 7 次迭代
% for elem in x:
....some stuff
% for item in y:
# inner loop
% if ${loop.index}==7:
yAYAYAYAYYAYA
% endif
...
% endfor
% endfor
I've tried slight variations and wrapping the index in a variable,but all that give me我尝试了细微的变化并将索引包装在一个变量中,但所有这些都给了我
mako.exceptions.SyntaxException: (SyntaxError) invalid syntax (<unknown>, line 1) (u'if ${loop.index}==7:pass')
Try if loop.index == 7:
${...}
syntax is used for resolving the value as html尝试
if loop.index == 7:
${...}
语法用于将值解析为 html
This should do it:这应该这样做:
%for idx, item in enumerate(y):
%if idx==7:
foo
%endif
%endfor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.