我有以下喘息模板:
@for i in pos:
@i[0] : @swi['x'] : @i[1]
@end
例如会输出:
Z:val:x
但是,我想做这样的事情:
@swi[@i[1]!s]
但它返回语法错误。我需要使用当前迭代数据在 swi 中查找。
Traceback (most recent call last):
File "toto.py", line 53, in <module>
template = engine.get_template('x')
File "/Soft/fox_dev/redhat/dist/other/lib/python2.6/site-packages/wheezy.template-0.1.151-py2.6.egg/wheezy/template/engine.py", line 41, in get_template
self.compile_template(name)
File "/Soft/fox_dev/redhat/dist/other/lib/python2.6/site-packages/wheezy.template-0.1.151-py2.6.egg/wheezy/template/engine.py", line 89, in compile_template
source, name)['render']
File "/Soft/fox_dev/redhat/dist/other/lib/python2.6/site-packages/wheezy.template-0.1.151-py2.6.egg/wheezy/template/compiler.py", line 26, in compile_source
source = adjust_source_lineno(source, name, self.source_lineno)
File "/Soft/fox_dev/redhat/dist/other/lib/python2.6/site-packages/wheezy.template-0.1.151-py2.6.egg/wheezy/template/comp.py", line 21, in adjust_source_lineno
source = compile(source, name, 'exec', ast.PyCF_ONLY_AST)
File "x", line 7
w(' '); w(i[0]); w(' : '); w(swi[@i[1]]); w(' : '); w(i[1]); w('\n')
^
SyntaxError: invalid syntax
我已经尝试过:
@swi[@i[1]!s]
@swi['@i[1]!s']
@swi[@i[1]]
@swi['@i[1]']
答案是:
@swi[i[1]]
我不知道为什么这里不允许使用@...
我是一名优秀的程序员,十分优秀!