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
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
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
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,
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):
>
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.