Filter

Darrell darrell at dorb.com
Tue Apr 11 19:51:59 EDT 2000


"Matthew" <shayman at uniserve.com> wrote in message
news:955427129.619305 at neptune.uniserve.ca...
> I need to write a filter that inserts tabs between Log values .  So that
> lines 1 to 3 come out looking something like lines 4 to 6.

import re, string

def tabIt(buf):
        # Markup that single letter
    buf=re.sub("(L11.*)([A-Za-z]) ","\g<1>\t\g<2>",buf)

    def twos(mo):
        """
        Add tabs to groups of two then remove extra tabs
        """
        g=mo.groups()
        g1=re.sub("(\w\w)","\t\g<1>\t",g[1])
        g1=re.sub("\t\t+","\t",g1)
        return g[0]+g1

    buf=re.sub("(L11)(.*)",twos,buf)
    return buf


print tabIt(open(fname).read())


--Darrell






More information about the Python-list mailing list