[Python-ideas] re.compile_lazy - on first use compiled regexes
Steven D'Aprano
steve at pearwood.info
Thu Mar 28 02:56:20 CET 2013
More information about the Python-ideas mailing list
Thu Mar 28 02:56:20 CET 2013
- Previous message: [Python-ideas] re.compile_lazy - on first use compiled regexes
- Next message: [Python-ideas] re.compile_lazy - on first use compiled regexes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 28/03/13 12:38, Chris Angelico wrote: > 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. No, you seem to have missed my point. I don't care whether we have a builder like re.compile() that turns a string into a regular expression object, or we use the RegExp type constructor directly. What I care about is that we don't recommend that people rely on the cache to handle that conversion, as Terry seems to be suggesting. -- Steven
- Previous message: [Python-ideas] re.compile_lazy - on first use compiled regexes
- Next message: [Python-ideas] re.compile_lazy - on first use compiled regexes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list