confusion about variable scope in a class
gyro
gyromagnetic at gmail.com
Sat Feb 14 10:53:46 EST 2009
Hi,
I was writing a Python script to perform some data analyses and was
surprised by some behavior I noted. A simple test program illustrating
the behavior is below.
I do not understand why the value of 'data' is being modified. I am
obviously missing something obvious, and would certainly appreciate an
explanation of why this is happening.
Thank you.
-gf
----------
#!/bin/env python
class TestPop(object):
def round1(self,data1):
t = data1.pop(-1)
def round2(self,data2):
t = data2.pop(-1)
def tester(self):
data = range(10)
self.round1(data)
print data
self.round2(data)
print data
if __name__ == '__main__':
tp = TestPop()
tp.tester()
More information about the Python-list
mailing list