[Python-ideas] String interpolation again.

INADA Naoki songofacandy at gmail.com
Fri Jul 23 16:16:00 CEST 2010


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.
’foo{bar}baz'.format(**vars()) or other technique is a bit trickey and messy.

If
  s = 'foo' bar 'baz'
is too dirty, another Pythonic way I think of are:

* s = str('foo', bar, 'baz')
This is not compatible current Python because str()'s second argument is
encoding and third argument is error handler.
I think Python4 should not accept str(a_bytes, 'utf-8') and use
a_bytes.decode('utf-8')

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

-- 
INADA Naoki  <songofacandy at gmail.com>



More information about the Python-ideas mailing list