[Python-ideas] String interpolation again.

INADA Naoki songofacandy at gmail.com
Fri Jul 23 19:52:18 CEST 2010


On Sat, Jul 24, 2010 at 2:06 AM, Masklinn <masklinn at masklinn.net> wrote:
> On 2010-07-23, at 16:16 , INADA Naoki wrote:
>> Basic problem is Python doesn't provide a way to print values of expression
>> into str like print prints to file.
>> 'foo{bar}baz'.format(bar=bar) is a bit bessy.
>
> I don't understand what you find messy about either this or `'foo{}baz'.format(bar)`.

In my code, '{bar}' and 'bar=bar' seems too verbose.
Your code is simple when the literal is short, but it is difficult to
check which variable
is inserted where when string is long.

>
>> * s = print('foo', bar, 'baz', sep='', file=None)
>> * s = print('foo', bar, 'baz', sep='', file=str)
>> Extend print() function to return str instead of print to file.
>>
>> * s = str.print('foo', bar, 'baz', sep='')
>> Add staticmethod to str.
>
> These forms can trivially be implemented as utility functions. And I don't see them as improvements enough to propose them for inclusion in the stdlib, but YMMV.

I agree with you.

-- 
INADA Naoki  <songofacandy at gmail.com>



More information about the Python-ideas mailing list