string generator

Terry Reedy tjreedy at udel.edu
Sun Jun 2 16:58:27 EDT 2002


"Gold Fish" <occeanlinux at linuxmail.org> wrote in message
news:3cfa8039_1 at news.iprimus.com.au...
> I like to create a list of file automatical based on series. For
example
> user input the number of file say 5. So i want to generate the file
> according to this range , this mean the generated files could be
> filename1
> filename2
> filename3
> filename4
> filename5
> I using the for loop like that
>
> for file in range(5):
>         lis = [file]
>         string.join('filename',lis[1:])
> how can it didn't work. I am confusing how to do it.

Perhaps you are looking for something like (untested):

define fileseries(basename, n):
  for i in range(n):
    yield basename+str(i)

Terry J. Reedy





More information about the Python-list mailing list