Dictionary Literals in Mako Expressions

Next, the syntax error is "unexpected EOF on parsing":

${foo({'bar':'baz'})} 

which, I suppose, is from an inner closing brace. This works great:

 ${foo(dict(bar='baz'))} 

but what is the syntax for using a dictionary literal?

+6
mako
source share
1 answer

From Brian Ryu to Mako Google Group Templates :

This is a long-awaited mistake; just use dict (). If you need a dictionary with keys that are not strings, convert the list of tuples to dict. for example instead:

${foo({1: 'a', 2: 'b'})}

do the following:

${foo(dict([(1, 'a'), (2, 'b')]))}

+6
source share

All Articles