कहा जाता है यदि आप किसी फ़ंक्शन के अंदर रेगेक्स संकलित करते हैं, और उस फ़ंक्शन को कई बार कॉल किया जाता है, तो क्या पाइथन प्रत्येक बार रेगेक्स को फिर से कंपाइल करता है, या पाइथन संकलित रेगेक्स कैश करता है (रेगेक्स मानता है बदल नहीं है)?एक फ़ंक्शन के अंदर एक रेगेक्स संकलित करना जिसे कई बार
उदाहरण के लिए:
def contains_text_of_interest(line):
r = re.compile(r"foo\dbar\d")
return r.match(line)
def parse_file(fname):
for line in open(fname):
if contains_text_of_interest(line):
# Do something interesting
आप सही हैं, [_compile फ़ंक्शन re.py] देखें (https://github.com/python/cpython/blob/master/Lib/re.py#L278) – pevik