unexpected behavior: did i create a pointer?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Sep 7 05:14:23 EDT 2007


En Fri, 07 Sep 2007 05:07:03 -0300, gu <pistacchio at gmail.com> escribi�:

> after two days debugging my code, i've come to the point that the
> problem was caused by an unexpected behaviour of python. or by lack of
> some information about the program, of course! i've stripped down the
> code to reproduce the problem:
>
> <code>
> a = {}
>
> for x in range(10):
>      for y in range(10):
>          a[x,y] = "0"
>
> copyOfA = a

copyOfA is *NOT* a copy - it's just another name pointing to the SAME  
object as a.
Python will never copy anything unless told explicitely.

Read this <http://effbot.org/zone/python-objects.htm>

-- 
Gabriel Genellina




More information about the Python-list mailing list