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
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to