gpt4 book ai didi

python - 喘息模板字典变量查找

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:57 25 4
gpt4 key购买 nike

我有以下喘息模板:

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

我不知道为什么这里不允许使用@...

关于python - 喘息模板字典变量查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21760517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com