file pointer array
Chris Rebert
clp2 at rebertia.com
Mon Jun 4 21:43:59 EDT 2012
On Mon, Jun 4, 2012 at 6:21 PM, FSH <lee.joosang at gmail.com> wrote:
> Hello,
>
> I have a simple question. I wish to generate an array of file
> pointers. For example, I have files:
>
> data1.txt
> data2.txt
> data3.txt
> ....
>
> I wish to generate fine pointer array so that I can read the files at
> the same time.
>
> for index in range(N):
> fid[index] = open('data%d.txt' % index,'r')
That loop will start at 0, not 1, so so you'll try to open "data0.txt".
To rectify that, use range(1, N+1), though you'll then need to use a
list comprehension like Ben Finney demonstrated.
Cheers,
Chris
More information about the Python-list
mailing list