Default Parameters to function!
sholden at bellatlantic.net
Thu Mar 16 03:08:10 CET 2000
Timothy Docker wrote:
> Michael Hudson <mwh21 at cam.ac.uk> writes:
> > "Yuriy Gorvitovskiy" <yuriy at centricsoftware.com> writes:
> > > I want to make a request to the Python developers to change the way of
> > > default parameters initialization from "when function definition is
> > > executed" to "when function executed".
> > Loosely speaking, no chance. Too much code relies on this behaviour
> > (yes, that's perhaps a bed idea, but it's still true).
> How much code really relies on this behaviour? The normal workaround
> for what people really want is as the manual suggests, ie:
> def f( x=None ):
> if x == None:
> x = 
> This would continue to work if defaults were evaluated at
> function application time. How much code is written like
> def f( x= ):
> x.append( 'vvv' )
> and expects to get the mutated value next time a default is needed?
> Not too much I suspect.
The real problem is setting the context in which the intialiser code will
run. Given that the scope of the definition and the scope of calls are
disjoint, it just doesn't make much sense to try to specify something
which will be meaningful when the call is executed.
"If computing ever stops being fun, I'll stop doing it"
More information about the Python-list