variable declaration
Nick Coghlan
ncoghlan at iinet.net.au
Tue Feb 8 05:37:15 EST 2005
Just wrote:
> In article <mailman.2152.1107854937.22381.python-list at python.org>,
> Nick Coghlan <ncoghlan at iinet.net.au> wrote:
>
>
>>Antoon Pardon wrote:ons already existing.
>>
>>>The compilor might generate a RESTORE instruction.
>>
>>Whether it is done as a LOAD/STORE or a RESTORE, it has to perform the same
>>work
>>- check the name exists in the local namespace, and throw an exception if it
>>doesn't. If it the name does exist, perform a normal store operation.
>
>
> But the compiler would _know_ in which scope the variable was defined,
> no?
I wouldn't expect the behaviour of name rebinding to be any different from other
forms of augmented assignment as far as the existence of the left-hand side goes.
Py> def f():
... x += 1
...
Py> f()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in f
UnboundLocalError: local variable 'x' referenced before assignment
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list