Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'attributes': 0.07; 'subject:code': 0.07; 'cc:addr:python-list': 0.10; '-tkc': 0.16; 'arbitrarily': 0.16; 'attr': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'wrote:': 0.17; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'subject:please': 0.27; "i'm": 0.29; 'could': 0.32; 'something': 0.35; 'there': 0.35; 'charset:us- ascii': 0.36; 'being': 0.37; 'subject:: ': 0.38; 'night': 0.62; 'dumb': 0.84; 'received:50.22': 0.84 Date: Thu, 28 Feb 2013 14:37:15 -0600 From: Tim Chase To: jkn+gg@nicorp.co.uk Subject: Re: suggestions for improving code fragment please In-Reply-To: References: X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com Cc: python-list@python.org 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362083739 news.xs4all.nl 6974 [2001:888:2000:d::a6]:59671 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40171 On 2013-02-28 19:47, The Night Tripper wrote: > Hi there > I'm being very dumb ... how can I simplify this fragment? > > > if arglist: > arglist.pop(0) > if arglist: > self.myparm1 = arglist.pop(0) > if arglist: > self.myparm2 = arglist.pop(0) > if arglist: > self.myparm3 = arglist.pop(0) > if arglist: > self.parm4 = arglist.pop(0) If they're arbitrarily named attributes of the "self", you could do something like for attr in ("myparm1", "myparm2", "myparm3", ...): if arglist: setattr(self, attr, arglist.pop(0)) else: break -tkc