opening more than 1 file

Skip Montanaro skip at mojam.com
Tue Apr 20 13:53:10 EDT 1999


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?

Well, how about:

    files = []
    for i in range(nfiles):
        files.append(open("/tmp/file%03d"%i, "wb"))

then access the i-th file as files[i]?

-- 
Skip Montanaro	| Mojam: "Uniting the World of Music"
http://www.mojam.com/
skip at mojam.com  | Musi-Cal: http://www.musi-cal.com/
518-372-5583




More information about the Python-list mailing list