Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!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: Fri, 15 Jan 2016 11:42:24 +0100 Lines: 33 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 pDI15cz7JDpEszqualquCA0JP63zTLpbhArrx98F2TSA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'problem?': 0.07; 'parsed': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'snippet': 0.09; 'subject:don': 0.09; 'python': 0.10; 'subject:python': 0.14; '(and,': 0.16; 'guessing': 0.16; 'module:': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'responses.': 0.16; 'wrote:': 0.16; 'fairly': 0.22; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'equivalent': 0.27; 'question': 0.27; 'idea': 0.28; 'perl': 0.29; 'received:132': 0.29; 'tail': 0.29; "i'm": 0.30; 'certainly': 0.30; 'guess': 0.31; 'supposed': 0.31; 'correctly': 0.34; 'something': 0.35; "isn't": 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'things': 0.38; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'more': 0.63; 'obvious': 0.76; 'smith': 0.76; 'otten': 0.84; 'p.s.:': 0.84; 'subject:find': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 132.230.195.61 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: 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:101741 On 15.01.2016 10:43, Peter Otten wrote: > Charles T. Smith wrote: > >> while ($str != $tail) { >> $str ~= s/^(head-pattern)//; >> use ($1); >> } > > For those whose Perl's a little rusty: what does this do? > A self-contained example might also be useful... > Right, an explanation would certainly get you a lot more responses. If I'm guessing correctly what the snippet is supposed to do (and, yes, my Perl definitely is rusty), isn't the Python equivalent of the regex part of your question fairly obvious if you're using the re module: things = [] while some_str != tail: m = re.match(pattern_str, some_str) things.append(some_str[:m.end()]) some_str = some_str[m.end():] # do something with things I have no idea why you'd want to *import* all the things parsed out of some_str, but for this part you may look at importlib.import_module. P.S.: the while loop above never ends if tail is not in some_str, but I guess your Perl snippet has the same problem?