1
我有以下喘息的模板:喘息模板字典變量查找
@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]']
發佈錯誤。 – njzk2
完成。錯誤在末尾添加 – user2346536
我假設你已經嘗試過'@swi [i [1]]'? – njzk2