Dynamic Zero Padding.
Larry Hudson
orgnut at yahoo.com
Tue Jun 7 21:46:48 EDT 2011
On 06/07/2011 03:01 PM, harrismh777 wrote:
> Ethan Furman wrote:
>> --> print("Testing %0*i" % (width, 1))
>
>> The '*' acts as a place holder for the width argument.
>
> very nice...
>
It works for precision as well as width.
wid = 10
prec = 3
num = 123.456789
print "%0*.*f" % (wid, prec, num)
gives you -> 000123.457
(It's the same as the printf() function in C.)
-=- Larry -=-
More information about the Python-list
mailing list