Is a list static when it's a class member?

Tom Plunket tomas at fancy.org
Tue Oct 10 20:55:38 EDT 2006


Fredrik Lundh wrote:

> if you want separate instances to use separate objects, make sure you 
> create new objects for each new instance.  see Tim's reply for how to
> do that.

kath's response is probably better.

In Python, you don't define the instance members in the class scope
like the OP has done:

> > class A:
> >     name = ""
> >     data = []

You define them when you attach them to an instance, e.g.

class A:
   def __init__(self):
      self.member1 = 'a'

   def ThisWorksToo(self):
      self.member2 = 'b'

# this also works
a = A()
a.member3 = 'c'

-tom!



More information about the Python-list mailing list