On Dec 2, 4:41 pm, "John Posner" <jjpos...@optimum.net> wrote:
>   Goal: place integer 456 flush-right in a field of width 8
>
>    Py2: "%%%dd" % 8 % 456
>    Py3: "{0:{1}d}".format(456, 8)
>
> With str.format(), you don't need to nest one formatting operation within  
> another. A little less mind-bending, and every little bit helps!

Or even "{:{}d}".format(456, 8), in 3.1 and 2.7 (when it appears).
But you can do this with % formatting, too.  In either 2.x or 3.x:

>>> "%*d" % (8, 456)
'     456'

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

Reply via email to