is this a bug? (python 2.3)

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Mar 9 17:03:14 EST 2007


En Fri, 09 Mar 2007 17:43:53 -0300, Carsten Haese <carsten at uniqsys.com>  
escribió:

>> 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
>
> http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list

Also see this more general topic:
http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects

-- 
Gabriel Genellina




More information about the Python-list mailing list