Python idiom: Multiple search-and-replace

Fredrik Lundh effbot at
Wed Apr 12 18:25:32 CEST 2000

Randall Hopper <aa8vb at> wrote:
> Thanks!  It's much more efficient.  The 140 seconds original running time
> was reduced to 11.6 seconds.  I can certainly live with that.

thought so ;-)

while you're at it, try replacing the original readline loop with:

    while 1:
        lines = fp.readlines(BUFFERSIZE)
        if not lines:
        lines = string.join(lines, "")
        lines = re.sub(...)

where BUFFERSIZE is 1000000 or so...


More information about the Python-list mailing list