Bulding arrays from text file data.

Chris Liechti cliechti at gmx.net
Tue Apr 30 19:41:03 EDT 2002


joe.woodward at padtinc.com (Joe Woodward) wrote in
news:28bbdc67.0204301518.5e7c41c8 at posting.google.com: 
> Does anyone know of a faster way to build an array out of text file
> with formatted data. What I have been doing works well, but now my
> files and 200MB and up. The following way builds a Numeric.array
> without knowing the size to start with. I can then resize it after the
> fact.
> 
> 
> yldpos=Numeric.array(map(float,re.split('\s+',string.strip(open('datafi
> le.txt').read())))) 

note that string.split() without args defaults to one or more whitespace 
too and i think its faster than an re.split

maybe it would also be faster if you read in blocks so that the strings 
which you split don't get too big. (maybe readlines(sizehint) with sizhint 
on 8192 or so)

don't know, but i would try it :-)

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list