Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Wolfgang Maier Newsgroups: comp.lang.python Subject: Re: Powerful perl paradigm I don't find in python Date: Mon, 18 Jan 2016 14:33:45 +0100 Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 0MKfOoTmrW9xwtte+f0ypALwxnIkeuPAMxUUkO3NY4EQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'matches': 0.07; 'valueerror:': 0.07; 'occurrences': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'simplified': 0.09; 'string)': 0.09; 'subject:don': 0.09; 'jan': 0.11; 'subject:python': 0.14; '14:05,': 0.16; '2016': 0.16; 'adjacent': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'try:': 0.18; 'ones.': 0.22; 'terminate': 0.22; 'pass': 0.22; 'header:In-Reply-To:1': 0.24; 'software.': 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'equivalent': 0.27; 'fri,': 0.27; '---': 0.28; 'initial': 0.28; 'figured': 0.29; 'perl': 0.29; 'received:132': 0.29; 'tail': 0.29; 'checked': 0.31; 'file': 0.34; 'except': 0.34; 'something': 0.35; 'totally': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:org': 0.37; 'version': 0.38; 'skip:p 20': 0.38; 'thank': 0.38; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'great': 0.63; 'you.': 0.64; 'it!': 0.64; 'antivirus': 0.66; 'smith': 0.76; 'avast': 0.84; 'subject:find': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 132.230.194.220 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: X-Antivirus: avast! (VPS 160103-1, 01/03/2016), Outbound message X-Antivirus-Status: Clean 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:101874 On 1/18/2016 14:05, Charles T. Smith wrote: > On Fri, 15 Jan 2016 14:20:17 +0100, Wolfgang Maier wrote: > >> pattern = pattern_str.compile() >> try: >> matches = pattern.findall(some_str, endpos=some_str.index(tail)) >> except ValueError: >> # do something if tail is not found >> pass > > Oh! I think that's it! > > > matches = findall (pattern, string) > for file in matches: > use (file) > > Totally cool! Thank you. > Great if it helps you. Just beware that this simplified version is not exactly equivalent to your initial perl snippet: Generally, findall will find ALL occurrences of pattern, not just adjacent ones. Since your perl example would never terminate if something non-matching is interleaved with pattern matches I figured you never expect that case. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus