is it a bug in Module copy or i am wrong??

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Nov 7 03:53:36 EST 2008


On Thu, 06 Nov 2008 23:59:51 -0800, yoma wrote:

> import copy
> 
> class A:
>     i = 1
> 
> class B:
>     a = A()
> 
> 
> b = B()
> 
> x=copy.copy(b)
> 
> y=copy.deepcopy(b)
> 
> print id(x.a), id(b.a)
> 
> print id(y.a), id(y.a)
> 
> the result:
> 14505264 14505264
> 14505264 14505264
> 
> So maybe i have a wrong understand to deep copy and shallow copy or it
> is  a bug ?

Additionally to Chris' explanation:  You will get the same `id()` for 
every "copy" of a 1 in CPython.  Numbers are immutable so the CPython 
implementation caches small integers as an optimization.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list