Huh? func_defaults, default values in function calls

Jeff Senn senn at maya.com
Wed Apr 12 17:14:41 CEST 2000


"Fredrik Lundh" <effbot at telia.com> writes:
> Mark Hathaway <hathawa2 at marshall.edu> wrote:
> > >> As a result, if you set a mutable object (list, dictionary, etc) as a
> > >> default, it'll be set when the function is defined and then if the
> > >> function changes it, it'll stay changed for subsequent invokations.
> > >> The function effectively has a "side-effect", of modifying it's own
> > >> default!
> >
> > This way you'll never really know what the default is going to be.
> 
> uhuh?  so you mean evaluating the default value every time the
> function is called would automatically make it easier to know what
> the default is going to be?  what about non-trivial default values?
> what about scoping?  what about side effects? what about per-
> formance?  etc.
> 
> > Ha ha ha ha. that's pathetic.
> 
> really?  I'm pretty sure Guido designed things this way on purpose,
...

Yep. Note (also) that you can use a non-mutable value as the
default if you don't want this behavior. Oh....I mean... if there *are*
such in things in the language...  maybe I should go wade into the
do-we-really-need-immutable-aggregates-in-Python argument....

...maybe not...;-) 

mutably-winkingly-
-Jas






More information about the Python-list mailing list