2

有人知道如何用 Mako 格式化字符串的长度吗?

相当于print "%20s%10s" % ("string 1", "string 2")

4

1 回答 1

7

您可以在 mako 中相当轻松地使用 python 的字符串格式

${"%20s%10s" % ("string 1", "string 2")}

给予:

>>> from mako.template import Template
>>> Template('${"%20s%10s" % ("string 1", "string 2")}').render()
'            string 1  string 2'
于 2009-06-22T23:53:51.680 回答