Re: default method parameter behavior

2008-04-02 Thread Primoz Skale
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I ran into a similar situation like the following (ipython session). > Can anyone please explain why the behavior? > Thanks in advance. > > In [11]: def foo(b=[]): > : b.append(3) > : return b > : > > In [12]:

Re: default method parameter behavior

2008-04-02 Thread Jerry Hill
On Wed, Apr 2, 2008 at 3:59 PM, <[EMAIL PROTECTED]> wrote: > I ran into a similar situation like the following (ipython session). > Can anyone please explain why the behavior? http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects Since you got bitten by this, you

Re: default method parameter behavior

2008-04-02 Thread Konstantin Veretennicov
On Wed, Apr 2, 2008 at 10:59 PM, <[EMAIL PROTECTED]> wrote: > I ran into a similar situation like the following (ipython session). > Can anyone please explain why the behavior? Of course. >From http://docs.python.org/ref/function.html: Default parameter values are evaluated when the function def

default method parameter behavior

2008-04-02 Thread jianbing . chen
I ran into a similar situation like the following (ipython session). Can anyone please explain why the behavior? Thanks in advance. In [11]: def foo(b=[]): : b.append(3) : return b : In [12]: foo() Out[12]: [3] In [13]: foo() Out[13]: [3, 3] In [14]: foo([]) Out[14]