How to isolate a constant?

Gnarlodious gnarlodious at gmail.com
Sat Oct 22 20:26:22 EDT 2011


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


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /