Friday, August 5, 2011

a note on scope

Found something interesting here: http://docs.python.org/tutorial/classes.html

If a name is declared global, then all references and assignments go directly to the middle scope containing the module’s global names. Otherwise, all variables found outside of the innermost scope are read-only (an attempt to write to such a variable will simply create a new local variable in the innermost scope, leaving the identically named outer variable unchanged).

That certainly explains what I saw a few days ago.

No comments:

Post a Comment