Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8482

Re: Default value for optional parameters unexpected behaviour?

Subject Re: Default value for optional parameters unexpected behaviour?
From Corey Richardson <kb1pkl@aim.com>
References <2a25a54a-c60b-4811-9c6a-97c7f717dccb@hd10g2000vbb.googlegroups.com> <BANLkTik3UP6j0z=+Ywq6LnTmKyhx_1mtrQ@mail.gmail.com> <A2.62.09596.320870E4@hrndva-omtalb.mail.rr.com>
Date 2011-06-26 15:23 -0400
Newsgroups comp.lang.python
Message-ID <mailman.431.1309116265.1164.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

Excerpts from Thomas L. Shinnick's message of Sun Jun 26 14:53:21 -0400 2011:
> See reference manual section 7.6  "Function definitions" under the 
> discussion subtitle "Default parameter values are evaluated when the 
> function definition is executed. "
>          http://docs.python.org/reference/compound_stmts.html#function-definitions
> 
> Yes, this is discussed in many places and many times, but why isn't 
> it in the Python FAQ?  Amazing, yes?
> 

Well, to be fair, I don't think most people actually read the FAQ.
The FAQ does say:

"Default arguments can be used to determine values once, at compile
time instead of at run time. This can only be done for functions or
objects which will not be changed during program execution..."

And he did modify the list during program execution. However this
isn't exactly forthright if you aren't looking for it / know what
you're reading.  I don't think it should be spilled out in detail but
maybe a "there are some tricks involved with mutable default
arguments (for example a list).  Refer to the language reference
(LINK) for more details" would be useful.

But I'm not really certain that would make much of a difference.
I'll Cc this to docs@python.org.
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
     -- Abraham Lincoln

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Default value for optional parameters unexpected behaviour? Marc Aymerich <glicerinu@gmail.com> - 2011-06-26 11:28 -0700
  Re: Default value for optional parameters unexpected behaviour? Shashank Singh <shashank.sunny.singh@gmail.com> - 2011-06-27 00:09 +0530
  Re: Default value for optional parameters unexpected behaviour? Corey Richardson <kb1pkl@aim.com> - 2011-06-26 14:36 -0400
  Re: Default value for optional parameters unexpected behaviour? Noah Hall <enalicho@gmail.com> - 2011-06-26 19:45 +0100
  Re: Default value for optional parameters unexpected behaviour? Terry Reedy <tjreedy@udel.edu> - 2011-06-26 14:46 -0400
  Re: Default value for optional parameters unexpected behaviour? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-06-26 12:21 -0700
  Re: Default value for optional parameters unexpected behaviour? Corey Richardson <kb1pkl@aim.com> - 2011-06-26 15:23 -0400

csiph-web