file pointer array
joncle at googlemail.com
Wed Jun 6 21:10:01 CEST 2012
On 06/06/12 19:51, MRAB wrote:
> On 06/06/2012 19:28, Jon Clements wrote:
>> On 06/06/12 18:54, Prasad, Ramit wrote:
>>> data= 
>>> for index in range(N, 1): # see Chris Rebert's comment
>>> with open('data%d.txt' % index,'r') as f:
>>> data.append( f.readlines() )
>> I think "data.extend(f)" would be a better choice.
> .extend does something different, and "range(N, 1)" is an empty range
> if N > 0.
Mea culpa - I had it in my head the OP wanted to treat the files as one
contiguous one. So yeah:
# something equiv to... (unless it is definitely a fixed range in which
# case (x)range can be used)
data = [ list(open(fname)) for fname in iglob('/home/jon/data*.txt') ]
# then if they ever need to treat it as a contiguous sequence...
all_data = list(chain.from_iterable(data))
More information about the Python-list