To clarify how Python handles two equal objects

Peter J. Holzer hjp-python at hjp.at
Wed Jan 11 15:26:22 EST 2023


On 2023-01-11 18:49:14 +0000, Stefan Ram wrote:
> Jen Kris <jenkris at tutanota.com> writes:
> >Each name has the same pointer
> 
>   ... from the C programmer's point of view.
> 
>   From the Python programmer's point of view, there are no "pointers".

That's just window dressing. Pointers are evil, so we can't have
pointers. So we'll just call them by a different name.


>   Instead, names or other targets are /assigned/ or /bound/ to objects.

This is the wrong way around. The name isn't assigned to the object. The
object is assigned to the name. As you quoted:

> |... the sequence is asked to assign the assigned object to
> |    its item with that index ...

Also, while the word "bind" is used in this manner in the official docs

> |... the name is bound to the object ...

and some members of this list, I think it is really misleading. It
sounds like the name is now an attribute of the object. But it isn't.
There is no way to the name (or the names) from the object. But there is
a way to get from the name the object. I can't think of a snappy,
unambiguous single verb to describe what's happening here, but do we
need one? We already have words like "assign", "refer", "point" with
fairly standardized meaning in IT. We can write that "a reference to an
object is assigned to a variable", and that after the assignment "the
variable refers to the object". Or we can even use the P-word. And since
we know that variables in Python can only contain references and never
values, we can abbreviate "a reference to an object" as "an object" in
most contexts.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20230111/9fab1f2f/attachment.sig>


More information about the Python-list mailing list