Reading in strings -> numbers ??

Louis M. Pecora pecora at anvil.nrl.navy.mil
Tue May 2 07:40:57 EDT 2000


In article <mtzoq9r57y.fsf at astron.berkeley.edu>, Johann Hibschman
<johann at physics.berkeley.edu> wrote:

> 
> Well, I've been doing numerics in python for years now, which is more
> than a little scary, and it's never been a problem for me.
> 
> I tend to either use Konrad Hinsen's ArrayIO module, which will semi-
> automatically do this for me, or simply do a
> 
>   lines = open(filename).readlines()
>   lines = map(string.split, lines)
>   lines = map(lambda l: map(float, l), lines)
>   data  = array(lines)
> 
> and I'm set.  Usually I write code like this once for any particular
> data format, then simply call it when I need it.
> 
> Whitespace-delimited files are very easy to parse with string.split.
> The column-oriented stuff you get from Fortran format statements is a
> bit harder, but it's easy enough to read in lines, take substrings,
> then evaluate those substrings as you need them.

Thanks, Johann.  I'm getting the suspicion that I should really get
acquainted with string.split.



More information about the Python-list mailing list