need fast parser for comma/space delimited numbers

Michael A. Miller mmiller3 at
Sun Mar 19 23:32:28 CET 2000

>>>>> "Les" == Les Schaffer <godzilla at> writes:

    > one issue for me is that my data files have some text at
    > the top which the test instrument spits out. so i would
    > need to specify where in the file the data starts.

You can specify a string containing characters in comment lines.
The mechanism is a bit crude in that any line containing any of
those characters is skipped.  You can skip your header by using
string.letters to flag comments,
i.e. TableIO.readColumns(filename,string.letters).  

    > also, i had looked at your module before. it was clear to
    > me how to specify comma-separated vs. whitespace separated.

At the moment only whitespace separated fields are handled.
TableIO does handle whitespace plus commas, as in "0.0, 0.1, 0.2"
but it does not handle comma-only delimited fields as in
"0.0,0.1,0.2".  There is a simple fix to allow that - ct should
be set to ", \t\n" rather than " \t\n".  I've made that change
and will put it on my web page asap.

    > finally, is it possible for your module to have the first
    > column of data be int's and the rest floats (though this is
    > not absolutely critical, it would be useful in certain
    > circumstances).

A simple way to convert to integers would be do something like:

  a, b, c = TableIO.readColumns( filename, string.letters )
  a = Numeric.array( a.tolist(), Numeric.Int )


Michael A. Miller                      mmiller3 at
  Krannert Institute of Cardiology, IU School of Medicine

More information about the Python-list mailing list