side effects on *some* default parameters

Jp Calderone exarkun at intarweb.us
Wed Feb 12 17:24:34 EST 2003


On Wed, Feb 12, 2003 at 04:43:34PM -0500, Joe Grossberg wrote:
> >On Wed, Feb 12, 2003 at 04:21:57PM -0500, Joe Grossberg wrote:
> >>I was tripped up by this quirk of Python, and I was wondering if you 
> >>guys could provide some insight.
> > http://www.python.org/doc/tut/node6.html
> > Jp
> >
> Thx -- I understand that Python does this, and I'm glad to see it's 
> documented. What I'm asking is *why* the language does this -- i.e. what 
> is the rationale for evaluating default arguments only once, especially 
> if it merited an "important warning"?

    *My* reason for why Python evaluates default arguments only once instead
of at every invocation is that it is easier to simulate the second given the
first than it is to simulate the first given the second.

  The actual reason is unknown to me, and may be as simple as "it is easier
to implement" or "I [Guido] like it this way".

  It is probably documented somewhere in the depths of one mailing list or
another.  Maybe someone who had a hand in it will deign to speak up now. :)

  Jp

-- 
        "I quite agree with you," said the Duchess; "and the moral of
that is -- Be what you would seem to be' -- or, if you'd like it put
more simply -- Never imagine yourself not to be otherwise than what it
might appear to others that what you were or might have been was not 
otherwise than what you had been would have appeared to them to be
otherwise.'"       -- Lewis Carrol, "Alice in Wonderland"
-- 
 up 4 days, 2:28, 2 users, load average: 0.00, 0.00, 0.00
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030212/5b936c45/attachment.sig>


More information about the Python-list mailing list