convert non-delimited to delimited

Matimus mccredie at gmail.com
Mon Aug 27 20:40:06 CEST 2007


On Aug 27, 10:59 am, RyanL <ryanlaurit... at gmail.com> wrote:
> I'm a newbie!  I have a non-delimited data file that I'd like to
> convert to delimited.
>
> Example...
> Line in non-delimited file:
> 0139725635999992000010100534+42050-102800FM-15+1198KAIA
>
> Should be:
> 0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
>
> What is the best way to go about this?  I've looked all over for
> examples, help, suggestions, but have not found much.  CSV module
> doesn't seem to do exactly what I want.  Maybe I'm just missing
> something or not using the correct terminology in my searches.  Any
> assistance is greatly appreaciated!  Using Python 2.4

I don't think you are going to find anything that will just do this
for you. You are going to have read the file, figure out where to
split the string, and reprint it delimited with commas. As for
suggesting code... I can't tell how you actually want to delimit the
stuff from the above example? Are the fields always a fixed number of
characters? If they aren't then is there some other method for
determining how many characters to group into a field? From the looks
of it you could split that string any way you want and get something
that looks right, but isn't.

Matt




More information about the Python-list mailing list