On Wed, 02 Dec 2009 13:34:11 -0500, Carsten Haese <carsten.ha...@gmail.com> wrote:


With string interpolation, you don't need to do that, either.
'%*d' % (8,456)
'     456'


Thanks, Carsten and Mark D. -- I'd forgotten about the use of "*" in minimum-field-width specs and precision specs (doh). How about this:

  "pi={1:.{0}f} e={2:.{0}f}".format(5, math.pi, math.e)

  (result: 'pi=3.14159 e=2.71828')

Can the Python2 %-formating facility handle this without repeating the "5" argument?

Even if it can, I stand by my original suggestion: include an example to show that the arguments to str.format() can be used on both the left and the right of a ":" in a replacement field.

-John
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to