Lists are weird when they are instance members
Robin Becker
robin at jessikat.fsnet.co.uk
Sat Jan 3 17:58:01 EST 2004
In article <ffHJb.5475$HL3.4277 at newssvr29.news.prodigy.com>, python
newbie <mesteve_b at hotmail.com> writes
I think you're not grokking that using
class A:
mylist = []
makes mylist a class attribute ie all instances share the same version
of mylist. To get an instance version you need to assign self.mylist.
That would normally be done using an __init__method. so
class A:
def __init__(self):
self.mylist = []
then each instance sets up its own empty list at creation time.
Hope that helps.
--
Robin Becker
More information about the Python-list
mailing list