[Python-ideas] String interpolation again.

Masklinn masklinn at masklinn.net
Fri Jul 23 19:06:52 CEST 2010


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)`.

> * 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.


More information about the Python-ideas mailing list