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
On Jan 12, 7:30 am, Jeremy wrote:
> On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote:
>
>
>
> > Jeremy schrieb:
>
> > > On Jan 11, 12:54 pm, Carl Banks wrote:
> > >> On Jan 11, 11:20 am, Jeremy wrote:
>
> > >>> I just profiled one of my Python scripts and discovered that >99% of
> > >>> the time wa
On Mon, 11 Jan 2010 13:51:48 -0800, Chris Rebert wrote:
> On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano
> wrote:
>> 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 tha
On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano
wrote:
> 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)
> regex.sub(new, source)
> # equi
Philip Semanchuk 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 makes.
The re module
Philip Semanchuk schrieb:
On Jan 11, 2010, at 3:30 PM, Jeremy wrote:
On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote:
Jeremy schrieb:
On Jan 11, 12:54 pm, Carl Banks wrote:
On Jan 11, 11:20 am, Jeremy wrote:
I just profiled one of my Python scripts and discovered that >99% of
the time w
On 2010-01-11, Steven D'Aprano 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 with a problem, think "I know,
>
On Jan 11, 2010, at 3:30 PM, Jeremy wrote:
On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote:
Jeremy schrieb:
On Jan 11, 12:54 pm, Carl Banks wrote:
On Jan 11, 11:20 am, Jeremy wrote:
I just profiled one of my Python scripts and discovered that
>99% of
the time was spent in
{built-in met
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
On Mon, Jan 11, 2010 at 15:02, Jeremy 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 each line is simpl
On Mon, 11 Jan 2010 11:20:34 -0800, Jeremy wrote:
> I just profiled one of my Python scripts
Well done! I'm not being sarcastic, or condescending, but you'd be AMAZED
(or possibly not...) at how many people try to optimize their scripts
*without* profiling, and end up trying to speed up parts
On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote:
> Jeremy schrieb:
>
>
>
>
>
> > On Jan 11, 12:54 pm, Carl Banks wrote:
> >> On Jan 11, 11:20 am, Jeremy wrote:
>
> >>> I just profiled one of my Python scripts and discovered that >99% of
> >>> the time was spent in
> >>> {built-in method sub}
> >>>
On Mon, Jan 11, 2010 at 12:02 PM, Jeremy 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
> suggestions on how they
Jeremy schrieb:
On Jan 11, 12:54 pm, Carl Banks wrote:
On Jan 11, 11:20 am, 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'm guessing this is re.sub (or
On Jan 11, 12:54 pm, Carl Banks wrote:
> On Jan 11, 11:20 am, 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'm guessing this is re.s
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 th
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
On Jan 11, 11:20 am, 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'm guessing this is re.sub (or, more likely, a method sub of an
internal object
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
19 matches
Mail list logo