40 lines
977 B
Plaintext
40 lines
977 B
Plaintext
From: gherron at aw.sgi.com (Gary Herron)
|
|
Date: Tue, 20 Apr 1999 18:43:44 GMT
|
|
Subject: opening more than 1 file
|
|
References: <371CB255.5FCAFBAF@solair1.inter.NL.net>
|
|
Message-ID: <371CCAE0.7DE87F8A@aw.sgi.com>
|
|
X-UID: 1365
|
|
|
|
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?
|
|
>
|
|
> Martin
|
|
|
|
|
|
If your definition of `elegant' includes `short', here is a one-liner to
|
|
do this. It maps a list [0,1,2,...] to a list of open files:
|
|
|
|
[<open file 'file00', mode 'w' at 100bb2e8>,
|
|
<open file 'file01', mode 'w' at 100bb338>,
|
|
<open file 'file02', mode 'w' at 100bb388>,
|
|
...]
|
|
|
|
files = map(lambda i: open("file%02d"%i, 'w'), range(N))
|
|
|
|
Then, files[i] gives the i'th file.
|
|
|
|
--
|
|
Dr. Gary Herron <gherron at aw.sgi.com>
|
|
206-287-5616
|
|
Alias | Wavefront
|
|
1218 3rd Ave, Suite 800, Seattle WA 98101
|
|
|
|
|
|
|
|
|