Question

How do I take the 'log' of a particular variable "testvar" in a Mako template? Assume that testvar is already a number. It does not appear clear in the documentation as to how one would do this.

Was it helpful?

Solution

You can import math inside the template, then call math.log:

>>> from mako.template import Template
>>> print Template("<%import math%>${math.log(testvar)}").render(testvar=2)
0.69314718056
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top