[Tutor] Please help

Alan G alan.gauld at freenet.co.uk
Wed Aug 3 19:01:00 CEST 2005


> sorry for repost.

OK, since nobody respoinded I'll make a few suggestions.


> I have a file (3339203 lines) that looks like this:

Get it working first then worry about tuning it for the volumes later.

>
> (col:1)    (col:2)     (col:3)

Is the above explanatory or part of the file?
Doesn't matter juch but just to be clear.

> AD134KL
>            XXXXX       XXXXX
>            Xaaaa       Xaaaa
>            Xbbbb       Xbbbb


> AD134KL
> AD134KL     XXXXX       XXXXX
> AD134KL     Xaaaa       Xaaaa
> AD134KL     Xbbbb       Xbbbb


So when you find a line with one field you need to store that
value and preppend it to all subsequent lines until you get
an empty line or another with a single field?

In pseudo code:

for line in infile
    if len(line) == 1:  # just a newline
       outfile.write(line)
       continue
    fields = line.strip().split()
    if len(fields) == 1
       tag = fields[0]
       output = line
    else:
       fields.insert(0,tag)
       output = "%12s%12s%12s\n" % tuple(fields)
    outfile.write(output)

Does that make any kind of sense?

Alan G.



More information about the Tutor mailing list