On 6/7/2011 7:05 PM, John Posner wrote:

You might want to try "new style" string formatting [1], which I think
is better than the "old style" in this particular case:

     >>> "Testing {0:0{1}d}".format(42, 4)
    'Testing 0042'
     >>> "Testing {0:0{1}d}".format(42, 9)
    'Testing 000000042'

One cannot use a nested field in the 'name' part of the field (before the ':' (I tried), but are pretty free to nest in the actual specification part after the ':'.

>>> '{0:{1}}'.format(7,'b')
'111'
>>> '{0:{1}}'.format(7,'d')
'7'

--
Terry Jan Reedy

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

Reply via email to