Re: Basic Class/Instance Question

2007-05-24 Thread Antoon Pardon
On 2007-05-23, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: >>> This is a FAQ. Default arguments are only evaled once - when the def >>> statement is evaled (which is usually at import time). The solution is >>> simple: don't use mutable objects as default arguments: >>

Re: Basic Class/Instance Question

2007-05-23 Thread Maric Michaud
Alan Franzoni a écrit : > Il 23 May 2007 04:53:55 -0700, Siah ha scritto: > > [cut] > > No. > > It's because the *body* of the function gets evaluated every time the > function is called, while the *definition* of the function gets evaluated > just once, when the function is 'declared'. > > You

Re: Basic Class/Instance Question

2007-05-23 Thread Alan Franzoni
Il 23 May 2007 04:53:55 -0700, Siah ha scritto: [cut] No. It's because the *body* of the function gets evaluated every time the function is called, while the *definition* of the function gets evaluated just once, when the function is 'declared'. Your issue arises when the default value of the f

Re: Basic Class/Instance Question

2007-05-23 Thread Siah
Bruno, I got my lesson today, first get your morning coffee before posting and of course avoid mutable objects as default arguments. Silly post, perhaps. Good to hear universe is in place. I should have rtffaq, though that's not why she left... Sia -- http://mail.python.org/mailman/listinfo/pyt

Re: Basic Class/Instance Question

2007-05-23 Thread Wildemar Wildenburger
Antoon Pardon wrote: >> This is a FAQ. Default arguments are only evaled once - when the def >> statement is evaled (which is usually at import time). The solution is >> simple: don't use mutable objects as default arguments: >> > > An immutable object would have given the same behaviour in

Re: Basic Class/Instance Question

2007-05-23 Thread Diez B. Roggisch
Siah wrote: > I think that's because: No idea what is because of what. Please quote essential parts of the posting you refer to. [] is [] > False () is () > True This is an implementation artifact. The interpreter chose to create only one instance for the empty tuple for optimization

Re: Basic Class/Instance Question

2007-05-23 Thread Siah
I think that's because: >>> [] is [] False >>> () is () True -- Sia -- http://mail.python.org/mailman/listinfo/python-list

Re: Basic Class/Instance Question

2007-05-23 Thread Antoon Pardon
On 2007-05-23, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Siah a écrit : >> Ready to go insane here. Class A, taking on a default value for a >> variable. Instantiating two separate objects of A() gives me a shared >> val list object. Just see the example bellow: >> >> >> class A(object): >

Re: Basic Class/Instance Question

2007-05-23 Thread Mike
Thanks Alan, I am still perplexed why the default value of this object is shared. hemm...d Back to programming, :) Sia On May 23, 7:19 am, Alan Franzoni <[EMAIL PROTECTED]> wrote: > Il 23 May 2007 04:07:19 -0700, Siah ha scritto: > > > Ready to go insane here. Class A, taking on a default value

Re: Basic Class/Instance Question

2007-05-23 Thread Bruno Desthuilliers
Siah a écrit : > Ready to go insane here. Class A, taking on a default value for a > variable. Instantiating two separate objects of A() gives me a shared > val list object. Just see the example bellow: > > > class A(object): > def __init__(self, val=[]): > self.val=val > > obj1 = A(

Re: Basic Class/Instance Question

2007-05-23 Thread Alan Franzoni
Il 23 May 2007 04:07:19 -0700, Siah ha scritto: > Ready to go insane here. Class A, taking on a default value for a __init__ is a function, taking a default value of [], which is a list, which is a mutable object. That said, you should remember that this means that such default value is 'shared'

Basic Class/Instance Question

2007-05-23 Thread Siah
Ready to go insane here. Class A, taking on a default value for a variable. Instantiating two separate objects of A() gives me a shared val list object. Just see the example bellow: class A(object): def __init__(self, val=[]): self.val=val obj1 = A() obj2 = A() print obj1 is obj2