Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33990
| Date | 2012-11-28 00:59 +0000 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: deepcopy questions |
| References | <bbed43a4-457d-45c3-bc84-519d51516431@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.325.1354064354.29569.python-list@python.org> (permalink) |
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?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
deepcopy questions lars van gemerden <lars@rational-it.com> - 2012-11-27 15:59 -0800
Re: deepcopy questions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-28 00:46 +0000
Re: deepcopy questions MRAB <python@mrabarnett.plus.com> - 2012-11-28 00:59 +0000
Re: deepcopy questions lars van gemerden <lars@rational-it.com> - 2012-11-28 01:05 -0800
Re: deepcopy questions Dieter Maurer <dieter@handshake.de> - 2012-11-29 08:01 +0100
csiph-web