anything like C++ references?

Stephen Horne intentionally at blank.co.uk
Mon Jul 14 05:51:10 CEST 2003


On Sun, 13 Jul 2003 22:42:21 GMT, "Bryan" <belred1 at yahoo.com> wrote:

>
>> 3.  Why is there no way to reference an immutable object via a
>> pointer, other than stuffing it into a mutable object designed for
>> some purpose other than simple pointer behaviour?
>>
>
>>>> a = (1, 2, 3)
>>>> b = a
>>>> id(a)
>15471760
>>>> id(b)
>15471760
>>>> print b[1]
>2
>>>>
>
>
>i just referenced an immutable object via a "pointer" and i __did_not__
>stuff it into a mutable object as you say.
>a and b "point" to the same object.

Technically, but what is the point? You can't do pointer-style things
with it. You can't change the object in any way without changing the
id, and you can't use the mechanism to, for instance, allow 'var'
parameters.

In short, you are showing evidence of the use of pointers internally
within Python, but that is not the same as providing pointer-like
semantics.





More information about the Python-list mailing list