In 开发者_如何学编程a Mako template, I need to do something like:
${'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'}}
When A do that, I get this error:
SyntaxException: (SyntaxError) unexpected EOF while parsing
(, line 1) ("'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'") in file…
How do I fix this issue?
I need to use this syntax in translated text:
$(_(u'foo bar %(a)s ... %(b)s) % { ... })
A work-around is to pass the dict object in a different way. For example:
from mako.template import Template
print Template("${'foo %(a)s bar %(b)s' % data}").render(data=dict(a='Alpha',b='Beta'))
Solution:
${'foo %(a)s bar %(b)s' % dict((('a', '1'), ('b', '2'),))}
精彩评论