This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author glubglub
Recipients glubglub
Date 2007-11-13.12:53:38
SpamBayes Score 0.058336005
Marked as misclassified No
Message-id <1194958418.68.0.123960070989.issue1437@psf.upfronthosting.co.za>
In-reply-to
Content
In the class below, 'arr' list should be unique for each instance of
class Blah. In reality, 'arr' is shared by all instances of 'Blah'

class Blah:
	arr = []    # this member should not be 
                    #   shared across all instances of blah
	s = ''

	def __init__(self, s):
		self.s = s

	def __str__( self):
		return '[%s, %s]' % (self.s, str(self.arr))

objs = []
objs.append(Blah('obj-a'))
objs.append(Blah('obj-b'))
objs.append(Blah('obj-c'))

# add to first object's array
objs[0].arr.append('abc')

# bug: 'abc' got added to all arrays
# print all arrays
for obj in objs:
	print obj

------------------------------
Actual Output:
[obj-a, ['abc']]
[obj-b, ['abc']]
[obj-c, ['abc']]

Expected Output:
[obj-a, ['abc']]
[obj-b, []]
[obj-c, []]
History
Date User Action Args
2007-11-13 12:53:38glubglubsetspambayes_score: 0.058336 -> 0.058336005
recipients: + glubglub
2007-11-13 12:53:38glubglubsetspambayes_score: 0.058336 -> 0.058336
messageid: <1194958418.68.0.123960070989.issue1437@psf.upfronthosting.co.za>
2007-11-13 12:53:38glubglublinkissue1437 messages
2007-11-13 12:53:38glubglubcreate