Newcomer question wrt variable scope/namespaces
Gary Duzan
gary.duzan at motorola.com
Fri Jan 13 12:14:30 EST 2006
Florian Daniel Otel wrote:
>
> My problem: I just discovered (by mistake) that attempting to assign a
> value to a non-local dictionary/list member does NOT generate an "
> UnboundLocalError" exception and the assignment is preserved upon
> exiting that scope (i.e. function). This would "violate" the python
> scoping rules where a variable in a global scope can only be
> referenced to (and not assigned to) -- unless declared as "global".
Right. However, assigning to a['foo'] modifies the object to which
'a' refers, not the 'a' variable itself. The rule is limited to the
rebinding of variables, not the modification of the objects to which
they refer.
Gary Duzan
Motorola CHS
More information about the Python-list
mailing list