deepcopy questions

lars van gemerden lars at rational-it.com
Tue Nov 27 18:59:38 EST 2012


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?

Cheers, Lars 




More information about the Python-list mailing list