You could do this using the pageargs
dictionary rather than eval
:
from mako.template import Template
print Template("hello ${pageargs['data{}'.format(0)]}!").render(data0="world")
However, from your example it sounds like you might have a bunch of variables each named like data0
, data1
, data2
, etc. Why not pass them to render as a list rather than as many similarly named variables? Something like:
`Template("hello ${data[0]}!").render(data=["world"])`)
Also see keep data out of your variable names.