Re: Using classes in python

2006-10-27 Thread Colin J. Williams
trevor lock wrote: > Hello, > > I've just started using python and have observed the following : > > class foo: > a=[] > def __init__(self, val): > self.a.append ( val ) > def getA(self): > print self.a > return self.a > > z = foo(5) > y = foo(4) >

Re: Using classes in python

2006-10-25 Thread Gabriel Genellina
At Wednesday 25/10/2006 16:19, trevor lock wrote: I've just started using python and have observed the following : class foo: a=[] def __init__(self, val): self.a.append ( val ) It's a common pitfall. As seen just a few days ago: http://groups.google.com/group/comp.lang.py

Re: Using classes in python

2006-10-25 Thread Éric Daigneault
trevor lock wrote: > Hello, > > I've just started using python and have observed the following : > > class foo: > a=[] > def __init__(self, val): > self.a.append ( val ) > def getA(self): > print self.a > return self.a > > z = foo(5) > y = foo(4) > z.

Using classes in python

2006-10-25 Thread trevor lock
Hello,I've just started using python and have observed the following :class foo:    a=[]    def __init__(self, val):    self.a.append ( val )    def getA(self):    print self.a    return self.az = foo(5)y = foo(4)z.getA()>> [5, 4]I was expecting that everytime I created an i