[Edu-sig] implementing summation notation (in Scheme & Python)
list-python-edu@ccraig.org
list-python-edu@ccraig.org
04 Jun 2001 13:52:58 -0400
Kirby Urner <pdx4d@teleport.com> writes:
> In doing this post, I discovered what I consider rather strange
> behavior in the nested scopes department and posted about it to
> comp.lang.python. Here's a copy of that post. Maybe someone here
> can help rationalize this behavior:
> [problem with name binding in nested scopes]
>From PEP227:
The name binding operations are argument declaration, assignment,
class and function definition, import statements, for statements,
and except clauses. Each name binding occurs within a block
defined by a class or function definition or at the module level
(the top-level code block).
If a name is bound anywhere within a code block, all uses of the
name within the block are treated as references to the current
block. (Note: This can lead to errors when a name is used within a
block before it is bound.)
augmented assignment is a 'name binding operation', which causes the
name 'a' to be used a a local variable in 'bar' rather than included
from the containing scope ('foo'). Note that this is done at compile
time, not runtime as you suggested (there isn't much of a difference
in Python, but there is one), because the function bar (like all
functions) was fully compiled before the call to it in foo.
--
Christopher A. Craig <list-python-edu@ccraig.org>
"Bah! Puny, weak newsreaders!"- GNUS info, in reference to 'global' kills