wheezy模板字典变量查找

时间:2014-02-13 16:55:35

标签: python

我有以下喘息模板:

@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]']

1 个答案:

答案 0 :(得分:1)

答案是:

@swi[i[1]]

我不确定为什么这里不允许@ ...