READ FILE UNTIL THE Xth SPACE IS ENCOUNTERED...

Janko Hauser jhauser at ifm.uni-kiel.de
Wed Oct 17 09:20:33 CEST 2001


Normally the data is ordered table like in the ascii-file. So reading
by line (xreadlines) and splitting by space (string.split) and map
(map) the float function to the resulting list is the straight-forward
way. But it becomes slow for files in the Mb range, because of the
loop but mainly for the many function calls for conversion. A pretty
fast module for reading table structured numbers is the TableIO
(google) package. Also scipy contains a specific function for doing
this. 

To your specific question, if the floats are formatted evenly, you can
utilize the byte argument of the file.read() method, to read an exact
number of bytes.

HTH,
__Janko


-- 
  Institut fuer Meereskunde             phone: 49-431-597 3989
  Dept. Theoretical Oceanography        fax  : 49-431-565876
  Duesternbrooker Weg 20                email: jhauser at ifm.uni-kiel.de
  24105 Kiel, Germany



More information about the Python-list mailing list