Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: suggestions for improving code fragment please (http://www.velocityreviews.com/forums/t958184-re-suggestions-for-improving-code-fragment-please.html)

Ian Kelly 02-28-2013 07:58 PM

Re: suggestions for improving code fragment please
 
On Thu, Feb 28, 2013 at 12:47 PM, The Night Tripper <jkn+gg@nicorp.co.uk> 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)


Perhaps this would work for you:

if arglist:
defaults = [self.parm1, self.parm2, self.parm3, self.parm4]
arglist = arglist[1:] + defaults[len(arglist)-1:]
self.parm1, self.parm2, self.parm3, self.parm4 = arglist[:4]


All times are GMT. The time now is 06:17 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.