Python idiom: Multiple search-and-replace
dgoodger at bigfoot.com
Wed Apr 12 23:21:54 EDT 2000
on 2000-04-12 12:25, Fredrik Lundh (effbot at telia.com) wrote:
> 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...
why not just,
lines = fp.read(BUFFERSIZE)
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 bigfoot.com Open-source projects:
- The Go Tools Project: http://gotools.sourceforge.net
(more to come!)
More information about the Python-list