Is a list static when it's a class member?
Fredrik Lundh
fredrik at pythonware.com
Wed Oct 11 01:22:41 EDT 2006
Tom Plunket 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.
so what's the practical difference between
def __init__(self, name):
self.name = name
self.data = []
and
def __init__(self, name):
self.name = name
self.data=[]
?
> In Python, you don't define the instance members in the class scope
> like the OP has done:
the OP's approach works perfectly fine, as long as you understand that
class attributes are shared.
</F>
More information about the Python-list
mailing list