From: CTO <debat...@gmail.com>
Date: Wed, 13 May 2009 16:03:34 -0700 (PDT)
Local: Wed, May 13 2009 7:03 pm
Subject: Re: [Python-ideas] Default arguments in Python - the return - running out of ideas but...
On May 13, 3:44 pm, Arnaud Delobelle <arno...@googlemail.com> wrote:
> On 13 May 2009, at 20:18, CTO wrote: Thanks for the input, but I've already written the code to do this. > > Why not just push for some decorators that do this to be included in > >>>> @Runtime > > This seems much more intuitive and useful to me than adding new > This is not possible. > def f(x=a**2+2*b+c): > is compiled to something very much like: > _tmp = x**2+2*b+c > So it is impossible to find out what expression yields the default > -- It is available at <URL:http://code.activestate.com/recipes/576751/>. For those with hyperlink allergies, the snippet posted above reevaluates the function whenever it is called, and can be used like so: >>> from runtime import runtime ... def example1(x, y=[]): >>> @runtime ... y.append(x) ... return y ... >>> example1(1) [2] [1] >>> example1(2) or, as posted above, >>> a, b, c = 0, 1, 2 ... def example2(x=a**2+2*b+c): >>> @runtime ... return x ... >>> example2() 29 4 >>> a = 5 >>> example2() The gode given is slow and ugly, but it does appear- Geremy Condra You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||