references and buffer()

Fredrik Lundh fredrik at pythonware.com
Sun Oct 8 15:22:51 EDT 2006


km wrote:

> ok so can i point a vairiable to an address location just as done in C 
> language ?

no.  there are no C-style "variables" in Python; just objects and names 
bound to objects.  Python variables are names, not memory locations.

>  >>> y = 'ATGCATGC'
>  >>> x = buffer(y)
>  >>> del(y)
>  >>> x
> <read-only buffer for 0xbf4cf0e0, size -1, offset 0 at 0xbf4cf240>
>  >>> print x
> ATGCATGC
> 
> now even when i delete y,  why is that x still exists ?

because it's an object.

> thats true even in the case of vairable assignment which states it a a 
> reference !
>  >>> a = 10
>  >>> b = a
>  >>> del(a)
>  >>> b
> 10
> i always thought if u modify the referred variable/buffer object it 
> should be reflected in the referenced variables/buffers objects . am i 
> wrong ?

reset your brain:

     http://effbot.org/zone/python-objects.htm

</F>




More information about the Python-list mailing list