What is built-in method sub

2010-01-11 Thread Jeremy
I just profiled one of my Python scripts and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list

Re: What is built-in method sub

2010-01-11 Thread Carl Banks
On Jan 11, 11:20 am, Jeremy jlcon...@gmail.com wrote: I just profiled one of my Python scripts and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? I'm guessing this is re.sub (or, more likely, a method sub

Re: What is built-in method sub

2010-01-11 Thread Matthew Barnett
Jeremy wrote: I just profiled one of my Python scripts and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list

Re: What is built-in method sub

2010-01-11 Thread MRAB
Jeremy wrote: I just profiled one of my Python scripts and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? I think it's the subtraction operator. The only way to optimise it is to reduce the number of subtractions

Re: What is built-in method sub

2010-01-11 Thread Jeremy
On Jan 11, 12:54 pm, Carl Banks pavlovevide...@gmail.com wrote: On Jan 11, 11:20 am, Jeremy jlcon...@gmail.com wrote: I just profiled one of my Python scripts and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize

Re: What is built-in method sub

2010-01-11 Thread Diez B. Roggisch
Jeremy schrieb: On Jan 11, 12:54 pm, Carl Banks pavlovevide...@gmail.com wrote: On Jan 11, 11:20 am, Jeremy jlcon...@gmail.com wrote: I just profiled one of my Python scripts and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way

Re: What is built-in method sub

2010-01-11 Thread Stephen Hansen
On Mon, Jan 11, 2010 at 12:02 PM, Jeremy jlcon...@gmail.com wrote: 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

Re: What is built-in method sub

2010-01-11 Thread Jeremy
was spent in {built-in method sub} What is this function and is there a way to optimize it? 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

Re: What is built-in method sub

2010-01-11 Thread Steven D'Aprano
of the code that don't matter while ignoring the actual bottlenecks. and discovered that 99% of the time was spent in {built-in method sub} What is this function You don't give us enough information to answer with anything more than a guess. You know what is in your scripts, we don't. I

Re: What is built-in method sub

2010-01-11 Thread J
On Mon, Jan 11, 2010 at 15:02, Jeremy jlcon...@gmail.com wrote: 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. Just curious, but if

Re: What is built-in method sub

2010-01-11 Thread Terry Reedy
On 1/11/2010 3:02 PM, Jeremy wrote: I am using the re.sub command to remove trailing whitespace from lines in a text file. help(str.rstrip) Help on method_descriptor: rstrip(...) S.rstrip([chars]) - str Return a copy of the string S with trailing whitespace removed. If chars is

Re: What is built-in method sub

2010-01-11 Thread Philip Semanchuk
and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? 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

Re: What is built-in method sub

2010-01-11 Thread Grant Edwards
On 2010-01-11, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: [regarding profiling results] I think you'll find that Python's regex engine is pretty much optimised as well as it can be, short of a major re-write. But to quote Jamie Zawinski: Some people, when confronted

Re: What is built-in method sub

2010-01-11 Thread Diez B. Roggisch
of my Python scripts and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? 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

Re: What is built-in method sub

2010-01-11 Thread Arnaud Delobelle
Philip Semanchuk phi...@semanchuk.com writes: I second the suggestion to use rstrip(), but for future reference you should also check out the compile() function in the re module. You might want to time the code above against a version using a compiled regex to see how much difference it

Re: What is built-in method sub

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: snip If you can avoid regexes in favour of ordinary string methods, do so. In general, something like: source.replace(target, new) will potentially be much faster than: regex = re.compile(target)

Re: What is built-in method sub

2010-01-11 Thread Steven D'Aprano
On Mon, 11 Jan 2010 13:51:48 -0800, Chris Rebert wrote: On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: snip If you can avoid regexes in favour of ordinary string methods, do so. In general, something like: source.replace(target, new) will

Re: What is built-in method sub

2010-01-11 Thread John Machin
Python scripts and discovered that 99% of the time was spent in {built-in method sub} What is this function and is there a way to optimize it? 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

Re: What is built-in method sub

2010-01-11 Thread Phlip
trailingPattern = '(\S*)\ +?\n' line = re.sub(trailingPattern, '\\1\n', line) What happens with this? trailingPattern = '\s+$' line = re.sub(trailingPattern, '', line) I'm guessing that $ terminates \s+'s greediness without snarfing the underlying \n. Then I'm guessing that