Nested function scope problem

Slawomir Nowaczyk slawomir.nowaczyk.847 at student.lu.se
Fri Aug 4 06:36:25 EDT 2006


On Thu, 03 Aug 2006 17:27:26 -0300
Gerhard Fiedler <gelists at gmail.com> wrote:

#> But seriously, for my comment this seems off-topic.

Well, you wrote "but it's not really understandable with a C++ concept
of variable". It is perfectly understandable to me. That's all I said
(or, at least, all I wanted to say).

#> I did not say that you can't create Python behavior with C (of
#> course you can, you can do /everything/ in C :). You can build
#> constructs made up of C variables that simulate everything that any
#> Python construct does. That's not the point. The point is how the
#> simple, built-in language variable behaves.

I agree.

For me, Python variable behaves just like a C++ variable (a pointer,
sure, but that's minor point to me... YMMV).

#> > #> You also don't expect the "identity" of a and b to be the same
#> > #> after assigning one to the other.
#> > 
#> > Don't I?
#> 
#> I don't know. Try replacing your printf statements with something
#> like "printf("%x %i %i\n",&a,a,*a);" and watch the first column.
#> The address operator is probably for a C programmer the closest to
#> what the id() function is to a Python programmer.

I disagree. At least in my understanding, which, up to now, was
perfectly enough to explain everything about how Python variables
behave:

The address operator in C is what textual representation (i.e. what
you type, like "a") is in Python. Equivalent of id() is a dereference
operator.

Of course, there are probably other ways to look at this. But I still
do not see why people claim that there is a significant difference
between what variables are in Python and in C++.

-- 
 Best wishes,
   Slawomir Nowaczyk
     ( Slawomir.Nowaczyk at cs.lth.se )

If at first you don't succeed, redefine success.




More information about the Python-list mailing list