problem with references
Uwe Mayer
merkosh at hadiko.de
Tue Jul 16 21:38:19 EDT 2002
In article <MPG.179e17ffdf2208d9989684 at news.rz.uni-karlsruhe.de>,
merkosh at hadiko.de says...
> !>> 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)
> ...
>
I did "some" more debuging and came to a more precise result /question.
The error is in the copy.deepcopy() call above, but the problem is
somewhere else.
The "element" class has a __deepcopy__() method which first makes a
shallow copy of self.element and then deepcopies of each mutable
instance variable. But, there is a problem with file objects. You can't
pickle file objects, however each element as an attribute ".file" which
takes up a file.
The __deepcopy__() method, beeing aware that file objects cannot be
copied, decided to set self.file to None. And *this* is my actual
problem. Setting self.file to None automatically sets the source
elements self.file (the one I'm making the copy from) to None - which is
perfectly right, because up until now those two objects are shallow
copies and refer to the same self.file objects.
Some lines afterwards the copied element is tried to be parsed, fails,
raises ParseError and is removed from the queue, leaving no trace of its
deeds, but setting the file attribute of the elements left in self.value
to None.
Now how am I supposed to just create a new "variable space" instead of
that shallow copy?
All I need is a way to loosen the reference the shallow copy created.
Please don't tell me that's not possible?!
Thanks in advance
Uwe
More information about the Python-list
mailing list