Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:both': 0.07; 'python:': 0.09; 'def': 0.12; 'name)': 0.16; 'name):': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'wrote:': 0.18; 'import': 0.22; 'this?': 0.23; 'header:User- Agent:1': 0.23; 'simpler': 0.24; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'george': 0.31; 'received:192.168.1.3': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; '(2)': 0.35; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'soul': 0.74; 'belief': 0.84; 'otten': 0.84 Date: Fri, 29 Mar 2013 09:49:34 -0400 From: Mitya Sirenef User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Doing both regex match and assignment within a If loop? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364564977 news.xs4all.nl 6938 [2001:888:2000:d::a6]:35285 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42244 On 03/29/2013 04:27 AM, Peter Otten wrote: > (2) > import re > > class Matcher: > def __call__(self, expr, line): > result = self.match = expr.match(line) > return result > def __getattr__(self, name): > return getattr(self.match, name) Perhaps it's a little simpler to do this? > self.match = expr.match(line) > return self.match -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Frisbeetarianism is the belief that when you die, your soul goes up on the roof and gets stuck. George Carlin