splitting tables

Skip Montanaro skip at pobox.com
Sat Feb 7 15:26:16 EST 2004


    r> The 'split' function works pretty well, except when there is an error in
    r> the original data table. For example if an element is missin in a line,
    r> like this:

    r> CGA 1990 08 15 13 16 G500-105 D   524.45 J.. R1 1993 01 29 00 00 900069
    r> CGA 1990 08 16 01 22          D   508.06 J.. R1 1993 01 27 00 00 900065

If the data are truly fixed width, just slice the strings:

    >>> s
    'CGA 1990 08 16 01 22          D   508.06 J.. R1 1993 01 27 00 00 900065'
    >>> s[0:3], s[4:8], s[9:11], s[12:14], s[15:17], s[18:20], s[21:29], s[30:31]
    ('CGA', '1990', '08', '16', '01', '22', '        ', 'D')

Skip




More information about the Python-list mailing list