Workaround for Python Issue 16609
Python 2.7 has an limitation whereby str(afloat)
causes unnecessary truncation (Issue 16609: http://bugs.python.org/issue16609). This causes:
print Template('${x}').render(x=1.0/3.0) 0.333333333333
which is only good to some 12 decimal places. It would be good if Mako could special-case the handling of floating point numbers to call repr
as opposed to str
. This issue is a particularly troublesome in the scientific Python community where Mako has found a place for generating source code (and hence the precision of substituted constants is important).
Comments (3)
-
-
I vote to close this issue. Python marked this as not an issue, so should mako. Secondly, even this report is entitled "work around", which shouldn't make it into library code at all costs. Work arounds belong in documentation or on stackoverflow.
-
- changed status to wontfix
agree. I often keep these open waiting for the poster to respond instead of closing the door on them....downside is I forget about them :)
- Log in to comment
make your own default filter which does this, if you want it automatic in all cases. Mako cannot provide an expensive filter like this by default.
In real world apps I always use explicit formatters in any case: