confusion about variable scope in a class

gyro gyromagnetic at
Sat Feb 14 16:53:46 CET 2009

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.



#!/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)
        print data
        print data

if __name__ == '__main__':
    tp = TestPop()

More information about the Python-list mailing list