[Tutor] Parsing text file?

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Apr 15 17:04:13 EDT 2004

>   I have finished the filter program which removes the header in
> file. I now need to remove the first column of data and then convert
> second.

If this is just for pratice in Python its OK. If you don't
have access to unix tools (even via cygwin) its also OK, but
if its a serious task then the unix cut command can do this
a lot easier, or even awk...

> Is parsing right for this?

Yes, but there are shades of parsing... Since your data is
regular spaced you can just use string slicing to extract the
characters you need, or alternatively the string split() method
will give you a list of the column data

> books on this?

There is a book by David Metz on Text Processing with Python.
Its available online for free too - try searching for Metz
and Text Processing Python...

> My data files looks like this:
> 16
> 1  1  0.00000  0.68337  0.25020
> 2  2  0.00000  0.29020  0.25020

Alan G.

More information about the Tutor mailing list