Beginner's performance problem
Mark Charsley
mark.charsley at REMOVE_THIS.radioscape.com
Thu Apr 11 09:32:00 EDT 2002
In article <slrnab68mh.15p.gerhard at lilith.my-fqdn.de>, gerhard at bigfoot.de
(Gerhard =?iso-8859-15?Q?H=E4ring?=) wrote:
> I haven't tried but an approach using the re module should be really
> fast, and shorter. Untested code follows:
>
> import re
> names = ["ALGORITHM_CLASS", ...]
>
> text = open("ThirteenThousandLines.sql").read()
> for name in names:
> regex = re.compile(name, re.I) # case insensitive search for name
> text = regex.sub(name, text) # replace all occurences
> print text
Aha! I'd put off reading up on the regular expression stuff until later as
I thought it just did searches, as opposed to also doing in-place
replaces. Half an hour spent on the HOW-TO and I'm a lot better informed.
Add a couple of r'\b' to the above, and I ought to be laughing.
TVM to everyone who helped.
--
Mark - personal opinion only, could well be wrong, not representing
company, don't sue us etc. etc.
More information about the Python-list
mailing list