[Python-ideas] re.compile_lazy - on first use compiled regexes
Chris Angelico
rosuav at gmail.com
Thu Mar 28 02:38:42 CET 2013
On Thu, Mar 28, 2013 at 12:25 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> We do this:
>
> x = Decimal(some_string)
> y = x**3
> z = x.exp()
>
> not this:
>
> y = Decimal(some_string)**3
> z = Decimal(some_string).exp()
>
> hoping that the string will be in a cache and the conversion will be fast.
> So why do we do this?
>
> result = re.match(some_string, text)
> other_result = re.match(some_string, other_text)
Would it be better if, instead of:
pat = re.compile(some_string)
it were spelled:
pat = re.RegExp(some_string)
? It'd match Decimal and so on, while still being exactly the same
thing ultimately - you turn the textual regex into an object.
ChrisA
More information about the Python-ideas
mailing list