deepcopy questions

MRAB python at mrabarnett.plus.com
Tue Nov 27 19:59:13 EST 2012


On 2012-11-27 23:59, lars van gemerden wrote:
> Hi,
>
> I get a very strange result when using deepcopy. The following code:
>
>      def __deepcopy__(self, memo):
>          independent = self.independent()
>          if independent is self:
>              out = type(self)()
>              out.__dict__ = copy.deepcopy(self.__dict__, memo)
>              print self.__dict__
>              print out.__dict__ #strange result
>              return out
>          else:
>              return copy.deepcopy(independent, memo).find(self.id).take()
>
> prints different results for self.__dict__ and out.__dict__:
>
> {'_active_': False, 'init': {}, '_id_': 0, '_items_': [<flow.library.collector object at 0x03893910>], '_name_': 'main'}
> {'_active_': False, 'init': {}, '_id_': 0}
>
> Two items are missing in the copy. Maybe i am missing something obvious, but i cannot figure out how this could happen.
>
> Can anyone tell me how this is possible?
>
I haven't been able to reproduce the problem.

Could you provide a self-contained and _runnable_ piece of code that
shows the problem?



More information about the Python-list mailing list