Best way to parse file into db-type layout?

Peter A. Schott paschott at no.yahoo.spamm.com
Thu Apr 28 19:34:31 EDT 2005


I've got a file that seems to come across more like a dictionary from what I can
tell.  Something like the following format:

###,1,val_1,2,val_2,3,val_3,5,val_5,10,val_10
###,1,val_1,2,val_2,3,val_3,5,val_5,11,val_11,25,val_25,967,val_967

In other words, different layouts (defined mostly by what is in val_1, val_2,
val_3).

The ,#, fields indicate what "field" from our mainframe the corresponding value
represents.

Is there a good way to parse this into a DB-type format where I only pull out
the values corresponding to the appropriate field numbers?  Seems like
converting to a dictionary of some sort would be best, but I don't quite know
how I would go about that.

In this case, the first field is a value unto itself - represents a "letter
type" that would be associated with the rest of the record.  The fields are
either present or not, no placeholder if there's no value for e.g. Field #4.

Thanks for any help or pointers you can give me.

-Pete



More information about the Python-list mailing list