Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: MRAB Newsgroups: comp.lang.python Subject: Re: psss...I want to move from Perl to Python Date: Sun, 31 Jan 2016 03:43:48 +0000 Lines: 31 Message-ID: Reply-To: MRAB Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de 7+fn3L4OqRkFjw42Twd62wxAXSRsvzlTJGf8wIslK8Jg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'cache': 0.05; 'res': 0.09; 'python': 0.10; '2016': 0.16; '>on': 0.16; '>to': 0.16; 'cached,': 0.16; 'distinct': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'gregory': 0.16; 'received:192.168.1.4': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'string': 0.17; '>>>': 0.20; 'gather': 0.22; 'parser': 0.22; 'slightly': 0.23; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'module': 0.25; 'header:User-Agent:1': 0.26; 'used,': 0.27; 'probably': 0.31; 'compiled': 0.32; 'point': 0.33; 'instead': 0.36; 'faster': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'january': 0.38; "won't": 0.38; 'application': 0.39; 'subject:from': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'header:Message-Id:1': 0.61; 'real': 0.62; 'lose': 0.63; 'matter.': 0.66; 'header:Reply-To:1': 0.67; 'sunday': 0.72; 'dozens': 0.84; 'subject:want': 0.93 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=K//fZHiI c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=kZ7UWmmPAAAA:8 a=B110WHEQI9L68cIR0S8A:9 a=AQyGIiR88GyjgdxV:21 a=Nmm9VXmUPrUQWRJN:21 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 In-Reply-To: <56ad69e4$0$14486$c3e8da3@news.astraweb.com> User-Agent: eM_Client/6.0.24432.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102329 On 2016-01-31 01:56:51, "Steven D'Aprano"=20 wrote: >On Sunday 31 January 2016 09:18, Gregory Ewing wrote: > >> Rustom Mody wrote: >>> 1. One can use string-re's instead of compiled re's >> >> And I gather that string REs are compiled on first use and >> cached, so you don't lose much by using them most of the >> time. > >Correct. The re module keeps a cache of the last N regexes used, for=20 >some >value of N (possibly 10?) so for casual use there's no real point to=20 >pre- >compiling other than fussiness. > In Python 3.5, it's 512. > >But if you have an application that makes heavy-duty use of regexes,=20 >e.g. >some sort of parser with dozens of distinct regexes, you might not want= =20 >to >rely on the cache. > It's slightly faster to use a pre-compiled regex because it won't have=20 to look it up in the cache, although most of the time it probably won't=20 matter.