Thursday, April 16, 2009

python global pre version 3

A snippet from the Python tutorial:

A special quirk of Python is that – if no global statement is in effect – assignments to names always go into the innermost scope. Assignments do not copy data — they just bind names to objects. The same is true for deletions: the statement del x removes the binding of x from the namespace referenced by the local scope. In fact, all operations that introduce new names use the local scope: in particular, import statements and function definitions bind the module or function name in the local scope. (The global statement can be used to indicate that particular variables live in the global scope.)

This may save a beginning Pythonista lots of subtle bugs later on. :)
nonlocal is a new language feature in version 3 that I will write about some time soon.

No comments: