Re: Class data being zapped by method
- From: Gary Herron <gherron@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 08 Aug 2006 12:50:28 -0700
arenium@xxxxxxxxx wrote:
Hi,Well, ... you have not told us the whole story here. This code works as expected.
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() # []
--------------------------------------------------------------------------
>>> class Foo():
.... def __init__(self):
.... self.data = []
.... def a_count(self):
.... print self.data
....
>>> bar = Foo()
>>> bar.data = [(-74.0015, 1), (123.451, 18)]
>>> print bar.data
[(-74.001499999999993, 1), (123.45099999999999, 18)]
>>> bar.a_count()
[(-74.001499999999993, 1), (123.45099999999999, 18)]
>>>
You effort to reduce your real code to a simple demonstration of the problem is appreciated, but I don't think it worked in this case.
Want to try again?
Gary Herron
.
- Follow-Ups:
- Re: Class data being zapped by method
- From: Kevin M
- Re: Class data being zapped by method
- References:
- Class data being zapped by method
- From: arenium
- Class data being zapped by method
- Prev by Date: Re: #!/usr/bin/python or #!/usr/bin/env python?
- Next by Date: newb question: file searching
- Previous by thread: Class data being zapped by method
- Next by thread: Re: Class data being zapped by method
- Index(es):
Relevant Pages
|