Re: mutable default parameter problem [Prothon]
Nice !
I wish Python had this, too.
Also, re-evaluating each time will allow one to use a global variable
whose value could change as a default parameter. Which looke suspicious.
Or something like that, which is GOOD :
class youpi( object ):
def mymethod( self, a=self.a, b=self.b ):
...
[color=blue]
> Pierre-Frédéric Caillaud wrote:
>[color=green][color=darkred]
>>> 2) Evaluate the default expression once at each call time when the
>>> default
>>> value is needed. The default expression would be evaluated in the
>>> context
>>> of the function definition (like a closure).[/color]
>>
>>
>> I like Choice 2 because I've always wanted to do the following :
>>
>> def func( x, y=2*x ):[/color]
>
> It looks like you will get your wish. The voting has been pretty much
> unanimous for option 2.
>
>[/color]
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nice !
I wish Python had this, too.
Also, re-evaluating each time will allow one to use a global variable
whose value could change as a default parameter. Which looke suspicious.
Or something like that, which is GOOD :
class youpi( object ):
def mymethod( self, a=self.a, b=self.b ):
...
[color=blue]
> Pierre-Frédéric Caillaud wrote:
>[color=green][color=darkred]
>>> 2) Evaluate the default expression once at each call time when the
>>> default
>>> value is needed. The default expression would be evaluated in the
>>> context
>>> of the function definition (like a closure).[/color]
>>
>>
>> I like Choice 2 because I've always wanted to do the following :
>>
>> def func( x, y=2*x ):[/color]
>
> It looks like you will get your wish. The voting has been pretty much
> unanimous for option 2.
>
>[/color]
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Comment