[Tutor] renumbering a sequence

Christopher Spears cspears2002 at yahoo.com
Sat Apr 4 21:37:15 CEST 2009


I want to write a script that takes a list of images and renumbers them with a user supplied number.  Here is a solution I came up while noodling around in the interpreter:

>>> alist = ["frame.0001.tif","frame.0002.tif","frame.0003.tif"]
>>> new_start = 5000
>>> for x in alist:
...     name, number, ext = x.split(".")
...     new_frame = name + "." + str(new_start) + "." + ext
...     new_start = new_start + 1
...     print new_frame
...
frame.5000.tif
frame.5001.tif
frame.5002.tif

How is that for a solution?  Is there a more elegant way to solve this problem?


      


More information about the Tutor mailing list