<br><div class="gmail_quote">On Thu, Oct 21, 2010 at 7:53 PM, John Nagle <span dir="ltr"><<a href="mailto:nagle@animats.com">nagle@animats.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On 10/21/2010 2:51 PM, Chris Rebert wrote:<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
On Thu, Oct 21, 2010 at 2:36 PM, Sean Choi<<a href="mailto:gnemnk@gmail.com" target="_blank">gnemnk@gmail.com</a>>  wrote:<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I found two similar questions in the mailing list, but I didn't understand<div class="im"><br>
the explanations.<br>
I ran this code on Ubuntu 10.04 with Python 2.6.5.<br>
Why do the functions g and gggg behave differently? If calls gggg(3) and<br>
g(3) both exit their functions in the same state, why do they not enter in<br>
the same state when I call gggg(4) and g(4)?<br>
<br>
# ---------------------------------------------------------------------- my<br>
code:<br>
def gggg(a, L=[]):<br>
</div></blockquote>
<br><div class="im">
This is a common newbie stumbling-block: Don't use lists (or anything<br>
mutable) as default argument values<br>
</div></blockquote>
<br>
    That really should be an error.<font color="#888888"></font></blockquote><div><br>Pylint warns about it.  I think that's enough.<br><br>I think it's enough, in part because unfortunately default values have become overloaded as the way of creating variables with a global lifetime, and sometimes that's useful to have.  I think it would probably have been better to make default arguments be evaluated once per function/method invocation, and add a static modifier to variables, but oh well.<br>
<br><br> <br></div></div>