Nested function scope problem

Gerhard Fiedler gelists at gmail.com
Sun Jul 30 10:18:10 EDT 2006


On 2006-07-30 09:54:14, Antoon Pardon wrote:

> Aren't you looking too much at implementation details now?

Possibly, but at this point I'm still trying to understand how Python does
these things, and what the useful abstraction level is for me. I also still
have very little experience how I'll put the things we've been discussing
here into (Python) practice. While not new to programming, I'm new to
Python.

> AFAIU, one can also build a C++ class hierarchy that with some small
> limitations in used operators, would have semantics very similar to
> Python. Would you argue that those using such a C++ class hierarchy would
> no longer be using variables in C++?

Probably not. But for me it's mostly about useful terminology, not
necessarily "correct" terminology. In order to talk about correct
terminology, we'd have to use a common definition of "variable". This is a
term so widely used that I'm not sure there is a useful single definition
of it; do you know one?

In any case, the following doesn't seem to be implementation detail (and
rather a part of the language), but it's not really understandable with a
C++ concept of "variable":

>>> a=3
>>> id(a)
3368152
>>> b=a
>>> id(b)
3368152
>>> b=4
>>> id(b)
3368140

You don't expect the "identity" of the variable b to change with a simple
assignment from a C/C++ point of view. You also don't expect the "identity"
of a and b to be the same after assigning one to the other. You can create
C++ classes that behave like that (you can implement Python in C++ :), but
that doesn't mean that you expect C++ language constructs to behave like
that.

Gerhard




More information about the Python-list mailing list