[Tutor] renumbering a sequence
spir
denis.spir at free.fr
Sun Apr 5 09:36:21 CEST 2009
Le Sat, 4 Apr 2009 20:05:41 -0400,
Kent Johnson <kent37 at tds.net> s'exprima ainsi:
> On Sat, Apr 4, 2009 at 3:37 PM, Christopher Spears
> <cspears2002 at yahoo.com> 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.
... and rename new_start (it's a new start number only as long as ==5000)
Denis
------
la vita e estrany
More information about the Tutor
mailing list