is this a bug? (python 2.3)

Sean McIlroy sean_mcilroy at yahoo.com
Fri Mar 9 15:32:17 EST 2007


hi all

when i run this code in python 2.3

######################  BEGIN CODE
class warfare:
    def __init__(self): self.pairs = [[0,0]]*2
    def __str__(self): return str(self.pairs)
    def setfirst (self,i,value): self.pairs[i][0] = value
    def setsecond(self,i,value): self.pairs[i][1] = value

w = warfare()
print w
w.setfirst(0,'hello')
print w
######################  END CODE

i get this result

######################  BEGIN ACTUAL RESULT
[[0, 0], [0, 0]]
[['hello', 0], ['hello', 0]]
######################  END ACTUAL RESULT

instead of the expected result

######################  BEGIN EXPECTED RESULT
[[0, 0], [0, 0]]
[['hello', 0], [0, 0]]
######################  END EXPECTED RESULT

is there a reasonable explanation for this behavior?

peace
stm




More information about the Python-list mailing list