generic text read function

les_ander at yahoo.com les_ander at yahoo.com
Thu Mar 17 21:50:55 EST 2005


Hi,
matlab has a useful function called "textread" which I am trying to
reproduce
in python.

two inputs: filename, format (%s for string, %d for integers, etc and
arbitary delimiters)

variable number of outputs (to correspond to the format given as
input);

So suppose your file looked like this
str1 5 2.12
str1 3 0.11
etc with tab delimited columns.
then you would call it as

c1,c2,c3=textread(filename, '%s\t%d\t%f')

Unfortunately I do not know how to read a line from a file
using the line format given as above. Any help would be much
appreciated
les




More information about the Python-list mailing list