Entry
Opening more than one file
Aug 9th, 2008 02:20
Sek Tea, Nathan Wallace, unknown unknown, Hans Nowak, Snippet 92, Skip Montanaro
"""
Packages: files
"""
"""
> 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:
"""
nfiles = 3 # your number of files here [PSST]
files = []
for i in range(nfiles):
files.append(open("/tmp/file%03d"%i, "wb"))
"""
then access the i-th file as files[i]?
"""
http://regalos-de-navidad.blogspot.com/
http://regalosdesanvalentin.blogspot.com/
http://ideas-para-regalar.blogspot.com/