deepcopy questions

lars van gemerden lars at
Wed Nov 28 00:59:38 CET 2012


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
            return copy.deepcopy(independent, memo).find(

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