[Python-ideas] re.compile_lazy - on first use compiled regexes

Ronny Pfannschmidt Ronny.Pfannschmidt at gmx.de
Fri Mar 22 23:31:40 CET 2013


Hi,

while reviewing urllib.parse i noticed a pretty ugly pattern

many functions had an attached global and in their own code they would 
compile an regex on first use and assign it to that global

its clear that compiling a regex is expensive, so having them be 
compiled later at first use would be of some benefit

but instead of all that reptetive code there should be an alternative to 
re.compile that waits with compilation for the first use

-- Ronny




More information about the Python-ideas mailing list