Scope, type and UnboundLocalError
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Sun Jul 9 16:58:15 EDT 2006
Paddy a écrit :
> Dennis Lee Bieber wrote:
>
>>On 9 Jul 2006 11:30:06 -0700, "Paddy" <paddy3118 at netscape.net> declaimed
>>the following in comp.lang.python:
>>
>>
>>>So,
>>>An assignment statement may assign an object to a name, in which case
>>>the name is 'tagged' as being local,
>>
>> Reverse... Python does not "assign" objects to names... It "assigns"
>>names to objects. One object can have multiple names.
>>
>> In the absence of a "global <name>" statement, any unqualified
>><name> found on the left side of an "=" is a local name (the name -- not
>>the object it is bound to -- is held as part of the current stack frame
>>and is removed on return from the function; the object may or may not be
>>garbage collected depending upon any other names bound to it).
>>
>> A qualified name is one with some sort of component specifier:
>><name>.<component>, <name>[<component>]. These access items that are
>>inside the object that <name> is bound on. The component access
>>basically is a function/method call telling the object itself to change
>>the <component> binding, not the top-level <name> binding.
>>
>
> Hi Dennis, in the last paragraph you do not state specifically where
> the name for the component name is looked for.
First in the local namespace, then in enclosing namespaces until the
global (read : module level) namespace, and finally in the builtins.
> Do you mean that for
> component name accesses,where the 'base' is not declared gobal, the
> 'base' name nevertheless is always looked for in the global scope?
unless it's found in another namespace before - same rules apply as for
a non-qualified name.
More information about the Python-list
mailing list