Python idiom: Multiple search-and-replace

David Goodger dgoodger at
Wed Apr 12 23:21:54 EDT 2000

on 2000-04-12 12:25, Fredrik Lundh (effbot at wrote:
> while you're at it, try replacing the original readline loop with:
> while 1:
> lines = fp.readlines(BUFFERSIZE)
> if not lines:
> break
> lines = string.join(lines, "")
> lines = re.sub(...)
> out_fp.write(lines)
> where BUFFERSIZE is 1000000 or so...

why not just,

    while 1:
        lines =
        if not lines:
        lines = re.sub(...)

? Saves the string.join() step. Or am I missing something? (I await

BTW, excellent idiom (especially the first one, represented by '...' above).
I can put it to immediate use. You've just sold another copy of your book
... as soon as it's Mac-friendly. And can I copy & paste from it? If not,
maybe I'll wait for the tree-killing edition.

David Goodger    dgoodger at    Open-source projects:
 - The Go Tools Project:
 (more to come!)

More information about the Python-list mailing list