problem with references

Uwe Mayer merkosh at hadiko.de
Tue Jul 16 15:46:40 EDT 2002


Hi,

I've got some object "Sequence" which takes one element and repeatedly 
appends copyies of this element into a queue.
Now, each element "has a condition" (f.e. self.value < 10).
Idea is to read in a file (something like someSequence.parse(<someFile>) 
). Sequence will propagate this call to all sub-elements. Sequence will 
continue to create sub-elements and instantly parse this sub-element 
(with something like element.parse(<someFile>)) until the first sub-
element raises an ParseError. Sequence will then test wether the number 
of elements in the queue is within a predefined range, otherwise it will 
raise a ParseError, too.

The above was necessary for you to understand what I'm doing. After a 
debugging session with pdb I found out that the following line creates 
the problem:

!>>         cpy = copy.deepcopy(self.element)
            try:
                cpy.parse(f)
            except ParseError:                 #reached maximum hits
	         ....
            else:
                if (<size of queue is ok>):
                    self.value.append(cpy)
                ...

This is a code fragment which creates a deep copy of a template object 
(stored in self.element) and then tries to parse this element. on 
success the copy is added to the queue (self.value).

However, this fails when Sequence goes for a second loop. Then cpy is 
overwritten with a second copy of the template, which also overwrites 
the value in the queue (self.value).

Why is that so and is there any way of stopping this? :)

Thanks for any help!

Uwe



More information about the Python-list mailing list