Class data being zapped by method

arenium at gmail.com arenium at gmail.com
Tue Aug 8 15:38:26 EDT 2006


Hi,

I'll cut to the chase.

I have a class named Foo(). I create an instance of this class named
bar, and I set bar.data to a large list of tuples.

Within Foo() there is a method which operates on self.data. I need to
call this method after I set self.data from the "outside" (bar.data),
which isn't a problem. However, I have found through simple debugging
procedures that while bar.data exists fine before the said method is
called, self.data within the class method is EMPTY. In my class
constructor I do declare self.data to be an empty list ([]), but
shouldn't self.data contain the populated list?

Basically...

--------------------------------------------------------------------------
class Foo():
    __init__(self):
        self.data = []
    a_count(self):
        ....
        print self.data
        ....

bar = Foo()
bar.data = [(-74.0015, 1), (123.451, 18), ...]
print bar.data # Get what I expect
bar.a_count() # []
--------------------------------------------------------------------------

This is a *highly* simplified version of what I'm actually doing. If
more code is needed just ask.

Thanks in advance.




More information about the Python-list mailing list