Friedrich:

<snip>

>> I would be much obliged if someone can give me some tips on how to
>> achieve a variably pad a number.
> :)
>
> ('%%0%dd' % (pads,)) % (n,)
>
> Probably be good to wrap it in a function.  It looks kind of obscure as it 
> is.

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'



HTH,
John

[1] http://docs.python.org/library/string.html, Section 7.1.2 "String
Formatting"

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

Reply via email to