Re: class attribute confusion

2010-12-05 Thread Steve Holden
On 12/3/2010 11:58 PM, Steven D'Aprano wrote: > Right. If you define a *class* attribute, it lives in the class, not the > instance, and so all instances share the same value. Unless, of course, an instance binds the same name in its namespace, in which case it will (usually) mask the class attri

Re: class attribute confusion

2010-12-04 Thread Steven D'Aprano
On Sat, 04 Dec 2010 15:00:43 +0100, Omar Abo-Namous wrote: >>> I think this behaviour is totally wrong, since it seems >>> A.__init__(self) is changing the value inside of A() not inside of the >>> object variable 'self' (that should be x or y)!! >> It's not wrong at all. You expect "mylist" to b

Re: class attribute confusion

2010-12-04 Thread Omar Abo-Namous
Am 03.12.2010 23:11, schrieb Arnaud Delobelle: OAN writes: Hi, i was having a problem with class attributes initiated outside of __init__. This code is a demonstration of what i mean: class A(): mylist = [] def __init__(self): self.mylist.append(1) pass class B(A

Re: class attribute confusion

2010-12-03 Thread Steven D'Aprano
On Fri, 03 Dec 2010 22:54:19 +0100, OAN wrote: > Hi, > > i was having a problem with class attributes initiated outside of > __init__. This code is a demonstration of what i mean: [...] > I would expect the following result: > > v: [1] > x: [1, 2] > y: [1, 2] > z: [1] > v: [1] > > Who wouldn't,

Re: class attribute confusion

2010-12-03 Thread Arnaud Delobelle
OAN writes: > Hi, > > i was having a problem with class attributes initiated outside of > __init__. This code is a demonstration of what i mean: > > class A(): > mylist = [] > def __init__(self): > self.mylist.append(1) > pass > > class B(A): > def __init__(self): >

class attribute confusion

2010-12-03 Thread OAN
Hi, i was having a problem with class attributes initiated outside of __init__. This code is a demonstration of what i mean: class A(): mylist = [] def __init__(self): self.mylist.append(1) pass class B(A): def __init__(self): A.__init__(self) self.