I'm wrong or Will we fix the ducks limp?
bc at freeuk.com
Mon Jun 6 17:55:26 EDT 2016
On 06/06/2016 17:19, Steven D'Aprano wrote:
> (2) The "variables are like boxes" metaphor applies to static languages like
> C and Pascal, where the compiler has knowledge of what variables will
> exist. Such languages allocate space for the variables at compile time,
> usually using fixed memory locations on the stack, or in registers, but
> rarely dynamically in the heap. That's exactly what Python doesn't do.
With sane programs of the kind I would write, variables appear in the
a = b
Thus they are known to the compiler and can be given special treatment
compared to any that there might be in an exec() string.
That the language allows the internal entries required for such names to
be 'deleted', or not to create them at all in code such as:
b = 10
(when cond is false) is another matter. A disassembly will clearly show
the name "b". And it would be ludicrous to suggest that here:
pass # 1
a = 0 # 2
pass # 3
"a" doesn't exist at all at line 1 or at the start of line 2, and only
comes fully into existence by line 3. "a" exists by name in the
byte-code as well as the source code from the start.
a is a variable.
More information about the Python-list