On 10/22/2011 8:46 PM, MRAB wrote:
On 23/10/2011 01:26, Gnarlodious wrote:
Say this:

class tester():
_someList = [0, 1]
def __call__(self):
someList = self._someList
someList += "X"
return someList

test = tester()

But guess what, every call adds to the variable that I am trying to
copy each time:
test()
[0, 1, 'X']
test()
[0, 1, 'X', 'X']
...
Python will copy something only when you tell it to copy. A simple way
of copying a list is to slice it:

someList = self._someList[:]

And another simple way:

    ...
    someList = list(self._someList)
    ...

Alan
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to