anything like C++ references?

Aahz aahz at pythoncraft.com
Sun Jul 13 21:40:32 EDT 2003


In article <usmp9q5s6.fsf at boost-consulting.com>,
David Abrahams  <dave at boost-consulting.com> wrote:
>Erik Max Francis <max at alcyone.com> writes:
>>
>> This is completely incorrect.  On the contrary, builtin types are
>> handled exactly uniformly in Python.  The only difference here is that
>> the builtin types that you've listed, along with some others, are
>> immutable, so you cannot change them if you have a reference to them.
>
>All you guys must be forgetting:
>
>   >>> a = [1]
>   >>> b = a
>   >>> a += b
>   >>> assert id(a) == id(b)
>   >>> a = 1
>   >>> b = a
>   >>> a += b
>   >>> assert id(a) == id(b)
>   Traceback...

I'm not forgetting that.  It's an unfortunate and tricky part of Python
semantics in some respects, but it's easily explained and understood if
you focus on the objects rather than the operation:

    a = foo
    b = a
    a = a.__iadd__(b)

Where id(a)==id(b) depends solely on the behavior of __iadd__().
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Not everything in life has a clue in front of it...."  --JMS




More information about the Python-list mailing list