I'm guessing this is re.sub (or, more likely, a method sub of an
internal object that is called by re.sub).
If all your script does is to make a bunch of regexp substitutions,
then spending 99% of the time in this function might be reasonable.
Optimize your regexps to improve performance. (We can help you if you
care to share any.)
If my guess is wrong, you'll have to be more specific about what your
sctipt does, and maybe share the profile printout or something.
Carl Banks
Your guess is correct. I had forgotten that I was using that
function.
I am using the re.sub command to remove trailing whitespace from lines
in a text file. The commands I use are copied below. If you have any
suggestions on how they could be improved, I would love to know.
Thanks,
Jeremy
lines = self._outfile.readlines()
self._outfile.close()
line = string.join(lines)
if self.removeWS:
# Remove trailing white space on each line
trailingPattern = '(\S*)\ +?\n'
line = re.sub(trailingPattern, '\\1\n', line)