[Python-ideas] String interpolation for all literal strings

Ron Adam ron3200 at gmail.com
Fri Aug 7 23:40:27 CEST 2015



On 08/07/2015 04:42 PM, Ron Adam wrote:
>
>        def _(value, fmt=''):
>            ('{:%s}' % fmt).format(value)

Hmmm, I notice that this can be rewritten as...

     _ = format
     'abc' + _(expr1) + 'def' + _(expr2) + 'ghi'


What surpised me is the docs say...

       format(format_string, *args, **kwargs)

But this works...

    >>> format(123, '^15')
    '      123      '

But this doesn't....

    >>> format('^15', 123)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: must be str, not int

Am I missing something, or do the docs need to be changed?

Cheers,
    Ron








More information about the Python-ideas mailing list