Nested Scopes unintended behaviour ?
Terry Reedy
tjreedy at udel.edu
Wed Mar 17 16:29:02 EDT 2010
On 3/17/2010 11:44 AM, Emile van Sebille wrote:
> On 3/17/2010 8:16 AM Michael Sparks said...
>> Hi,
>>
>>
>> Is the following behaviour expected ?
>
> In short, yes. Assignment within a function forces the variable to
> locals.
In 3.x, one can declare names to be nonlocal (ie, local to some outer
function, as opposed to local to the current function or module global).
In your case,
nonlocal on
in your inner swtchfun function would give the behavior you wanted.
Terry Jan Reedy
More information about the Python-list
mailing list