[Tutor] more fun and games with padded numbers

Christopher Spears cspears2002 at yahoo.com
Fri Jan 12 01:03:19 CET 2007


Let's say I have a series of files that are named like
so:

0001.ext
0230.ext
0041.ext
0050.ext

How would I convert these from a padding of 4 to a
padding of 1?  In other words, I want the files to be
renamed as:

1.ext
230.ext
41.ext
50.ext

At first I used strip(), which was a mistake because
it removed all the zeroes.  

The only other solution I can think of is to use
slicing to slice off the zeroes.  Perhaps I could loop
through the name and remove zeroes until I hit a
number that is not zero and then exit the loop.

Any hints or suggestions?
 


More information about the Tutor mailing list