The “does Python have variables?” debate

Marko Rauhamaa marko at pacujo.net
Thu May 8 16:06:27 EDT 2014


Terry Reedy <tjreedy at udel.edu>:

>> On Thu, May 8, 2014 at 6:07 PM, Joseph Martinot-Lagarde
>> <joseph.martinot-lagarde at m4x.org> wrote:
>>> For me, names bound to values is the same concept as pointer
>>> pointing to memory.
>
> You are missing a level of indirection. In CPython, a name (always in
> some namespace) represents a pointer to a pointer. The first pointer
> is calculated as an offset from the base pointer of the namespace. For
> a C array namespace (used for functions), the offset is constant (for
> that function and namespace). For a python dict namespace, the offset
> is calculated from the hash of the name, the size of the dict, and the
> previous contents of the hash table. This complication allows the
> namespace to grow and shrink. In either case, the second pointer if
> overwritten to 'rebind' the name.

Terry, you are talking about an implementation. Joseph is talking about
the concept.

You can tell a C programmer that a Python variable always holds a
pointer to an object, and they get the idea right away ("Oh, so '.' in
Python is the same as '->' in C") and start producing efficient, correct
Python code.


Marko



More information about the Python-list mailing list