Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dictionary literals in Mako expressions

Tags:

mako

The following throws a syntax error, "unexpected EOF while parsing":

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

which I guess is from the inner closing curly brace. This works fine:

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

but what's the syntax for using a dictionary literal?

like image 405
Hollister Avatar asked Jan 06 '11 20:01

Hollister


1 Answers

From Brian Rue on the Mako Templates Google Group:

This is a long-outstanding bug; just use dict(). If you need a dictionary with keys that aren't strings, convert a list of tuples into a dict. e.g. instead of this:

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

do this:

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

like image 163
Hollister Avatar answered Sep 23 '22 17:09

Hollister