[plug] [OT] Adding leading zeros in python

Cameron Patrick cameron at patrick.wattle.id.au
Tue Dec 21 16:55:35 WST 2004


rpowersau at gmail.com wrote:

> >>> for i in range(1,21):
> ...   localf = 'file%2s' %i

Try 'file%.2d' (note the decimal point).  It's almost the same as C
printf format strings, so man 3 printf may be of use (as well as the
Python on-line docs).

Cameron.




More information about the plug mailing list