opening more than 1 file
Martin van Nijnatten
euroibc at solair1.inter.NL.net
Wed Apr 21 05:43:43 EDT 1999
Thanks, this answers my question.
I want to read the files, and they have to be open simultaneously because I
want to
merge the records/lines in the files into 1 file (after I made some changes
to certain fields)
Martijn Faassen wrote:
> martin van nijnatten wrote:
> >
> > I have a variable, which can have a value in the range from 1 to 20.
> >
> > If the value is 7, I have to open 7 files.
> >
> > What could be an elegant way of doing this?
>
> It's hard to say without more details -- what names do you want these
> files to have, for instance? Do you want to read the files, or write to
> them? The basic idea could be something like:
>
> def openfiles(howmany):
> opened_files = []
> for i in range(howmany):
> opened_files.append(open("prefix%s" % i, "r"))
> return opened_files
>
> This returns a list with file objects.
>
> Why is it necessary to open so many files simultaneously anyway? Perhaps
> I misunderstood. :)
>
> Regards,
>
> Martijn
More information about the Python-list
mailing list