23 Mar
2013
23 Mar
'13
6 p.m.
On 2013-03-23, at 16:33 , Antoine Pitrou wrote:
On Sat, 23 Mar 2013 16:30:39 +0100 Masklinn
wrote: Right, but in this case while I called it a cache the semantics really is a lazy singleton: only create the regex object when it's needed, but keep it around once it's been created.
Perhaps we need a functools.lazy_compute() function:
pat = functools.lazy_compute(re.compile, r"my very long regex")
Yes, I'm not even sure the argument is needed: functools.partial (or a lambda) can be used for that and lazy_compute/compute_once would take a function of arity 0 as parameter.