opensubscriber
   Find in this group all groups
 
Unknown more information…

p : python-list@python.org 23 October 2011 • 8:26AM -0400

How to isolate a constant?
by Gnarlodious

REPLY TO AUTHOR
 
REPLY TO GROUP




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']


Can someone explain this behavior? And how to prevent a classwide
constant from ever getting changed?

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

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.