【问题标题】:Formatting with mako使用 mako 格式化
【发布时间】:2010-11-05 00:33:49
【问题描述】:

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

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

【问题讨论】:

    标签: python template-engine mako


    【解决方案1】:

    你可以在 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'
    

    【讨论】:

      猜你喜欢
      • 2012-12-15
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      相关资源
      最近更新 更多