Parsing data

Eric Brunel eric.brunel at pragmadev.com
Mon Apr 7 12:02:08 EDT 2003


Antonis Kaklis wrote:
> hello to everybody...
> 
> A have a file with values ordered by columns:
> Say (e.g force values, in time steps of 0.0200sec)
> 
>    .2161473E-05   .2183854E-05   .2177804E-05   .2174099E-05   .2254829E-05
>    .2145163E-05   .2322683E-05   .2112049E-05   .2092585E-05   .2069618E-05
>    .2052460E-05   .2572402E-05   .2625725E-05   .2701999E-05   .2771539E-05
>    .1884220E-05   .1864868E-05   .1835972E-05   .3150803E-05   .3245766E-05
>    .3343058E-05   .3437211E-05   .3543562E-05   .1512718E-05   .1483842E-05
>    .1440723E-05   .1408216E-05   .1363429E-05   .1340211E-05   .1291136E-05
>    .1260124E-05   .4968635E-05   .5089609E-05   .5228032E-05   .5364493E-05
>    .7569464E-06   .7437904E-06   .5947033E-05   .5593801E-06   .6339938E-05
>    .6471278E-05   .2300983E-06   .1903562E-06   .1526042E-06   .7414982E-05
>      ...            ...              ...          ...              ...
> 
> how can i parse the values (in order to proccess or plot or whatever else i
> want)
> of a structure like that?

for line in file('data.txt'):
   print [float(x) for x in line.split()]

?

(NB: for older Python versions, you'd better do:

for line in open('data.txt').xreadlines():
   print [float(x) for x in line.split()]
)

Was that what you wanted? What you want to do with your data is not quite clear 
from your post...
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list