Line Text Parsing

allanc kawNOSPAMenks at nospamyahoo.ca
Wed Feb 4 14:35:52 EST 2004


I'm new with python so bear with me.

I'm looking for a way to elegantly parse fixed-width text data (as opposed 
to CSV) and saving the parsed data unto a database. The text data comes 
from an old ISAM-format table and each line may be a different record 
structure depending on key fields in the line.

RegExp with match and split are of interest but it's been too long since 
I've dabbled with RE to be able to judge whether its use will make the 
problem more complex.

Here's a sample of the records I need to parse:

01508390019002      11284361000002SUGARPLUM
015083915549           SHORT ON LAST ORDER 
0150839220692 000002EA BMC   15 KG   001400

1st Line is a (portion of) header record.
2nd Line is an text instruction record.
3rd Line is a Transaction Line Item record.

Each type of record has a different structure. But these set of lines 
appear in the one table.


Any ideas would be greatly appreciated.

Allan



More information about the Python-list mailing list