[Python-3000] The meaning of "global variable"
Georg Brandl
g.brandl at gmx.net
Sun Nov 5 23:59:35 CET 2006
Marcin 'Qrczak' Kowalczyk wrote:
> Ron Adam <rrr at ronadam.com> writes:
>
>> By not limiting parent to just the parent scope you create exceptions. The rule
>> becomes:
>>
>> The keyword (*)nonlocal designates a name will be written to in the
>> closest enclosing "parent" scope *except* when a pre-existing matching name
>> exists in a scope further up.
>>
>> To me that is more confusing than always referring to the closest enclosing
>> scope without exception.
>
> The rule should be:
>
> The keyword 'nonlocal' causes the lookup to be performed as if there
> were no assignments to that variable in the scope containing the
> 'nonlocal' declaration.
Plus, if there's no binding in an enclosing scope, an error is raised.
(Which brings up the assymetry to today's global again, but is that really
a problem?)
Georg
More information about the Python-3000
mailing list