"Kevin Smith" <Kevin.Smith at sas.com> wrote in message
news:20030124111855332-0500 at braeburn.themorgue.org...
> I have a program that creates a large object consisting of nested
lists.
> I then cache certain instances (which correspond to sections) of
that
> object into a smaller list. Then I process the document in various
ways
> using the smaller list to jump to the sections in the large object.
> This worked fine in Python 2.0, but doesn't in Python 2.2. Here is
a
> simplified version of the offending code:
>> def sectionsBefore(self):
> """ Return a list of sections that occur before 'self' in the
> document """
> list = []
> # Walk through cached document sections list
> for section in self.documentSections():
It strikes me as a little odd that a method returning the entire list
of sections should be a method of each section in that list...
However: 2.2 did change (generalize) the meaning and inplementation of
'for i in iterable' (new meaning). This should not have changed the
result of old code, but maybe you found a wierd corner case. One
would have to see the method to speculate more. Your problem may
arise earlier than this.
> # This 'if' block works in Python 2.0, but not in Python 2.2.
> # For some reason, in Python 2.2, 'self' isn't equivalent to
'section'
> # at any point even though they appear to point to the same object
> # based on other criteria (i.e. result of calling other methods).
> # If 'self' is the same object as 'section', then break
> # out and return the current list of sections.
> if section is self:
Have you verified that this is true (in 2.2) on creation of the
instance where this is not true. Is the problem with just one or some
instances or all? Does output of documentSections() stay constant?
> list.reverse()
> return list
> # Keep looking.
> else:
> list.append(i)
> list.reverse()
> return list
>> Does anyone know what occurred in Python 2.2 to make this not work
> anymore?
My suggestion: explore some more with print statements (or the
debugger) to isolate when mismatch is first apparent.
Terry J. Reedy