用 mako 格式化 [英] Formatting with mako
本文介绍了用 mako 格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何用 Mako 格式化字符串的长度吗?
相当于print "%20s%10s" % ("string 1", "string 2")?
解决方案
您可以在 mako 中相当轻松地使用 python 的字符串格式
${"%20s%10s" % ("string 1", "string 2")}
给予:
<预><代码>>>>from mako.template 导入模板>>>Template('${"%20s%10s" % ("string 1", "string 2")}').render()'字符串 1 字符串 2'Anyone know how to format the length of a string with Mako?
The equivalent of print "%20s%10s" % ("string 1", "string 2")?
解决方案
you can use python's string formatting fairly easily in mako
${"%20s%10s" % ("string 1", "string 2")}
giving:
>>> from mako.template import Template
>>> Template('${"%20s%10s" % ("string 1", "string 2")}').render()
' string 1 string 2'
这篇关于用 mako 格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文