Nested function scope problem

Gerhard Fiedler gelists at gmail.com
Thu Jul 27 15:40:25 EDT 2006


On 2006-07-27 14:15:34, Dennis Lee Bieber wrote:

>> In a language like C the name doesn't hold anything either. The name is
>> just a way for refering to a memory space which will hold something. 
>> 
> 	Except for one difference... In C (and most other languages) that
> memory space is FIXED -- name "X" ALWAYS refers to memory space "Y".

Not really fixed, at least not for local variables. They sit at variable
places, which can be (and usually are) different for every invocation of a
function. Maybe "stack-fixed"...

Not sure this is relevant, but I felt it needed to be said :)


> 	In Python, even the location of the "name" may vary -- if you "del
> name" then do some operations and rebind "name", the new "name" itself
> could be somewhere else in memory.

In this respect, a Python var is similar to a C pointer var. The same thing
you are describing here can be done with a C pointer. Allocate storage
("bind" it) and have a pointer referencing it. Do something with it.
Deallocate it ("del it"). Allocate other storage and have the same pointer
referencing it ("rebind it"). The referenced area is somewhere else now
(usually). 

Gerhard




More information about the Python-list mailing list