On Sat, Apr 4, 2009 at 3:37 PM, Christopher Spears
<[email protected]> wrote:
>
> 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

You might want to sort the list, depending on where it came from:
alist.sort()

>>>> for x in alist:
> ...     name, number, ext = x.split(".")
> ...     new_frame = name + "." + str(new_start) + "." + ext

You could use string formatting here;
new_frame = '%s.%s.%s' % (name, new_start, ext)

> ...     new_start = new_start + 1

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?

It's fine.

Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to