[BangPypers] Does Python have lexical scoping?
Senthil Kumaran
senthil at uthcode.com
Sun Nov 9 22:57:07 CET 2014
On Sun, Nov 9, 2014 at 1:14 AM, Noufal Ibrahim KV <noufal at nibrahim.net.in>
wrote:
> How is lexical scoping with a mutable environment different from dynamic
> scoping?
>
I think you should post this in python-dev and you might get answers with
rigorous definitions.
Here is my short snippet which shows a behavior which does not indicate a
dynamic binding nature.
# example.py
x = 10
y = lambda: x
def f():
x = 20 # This is not rebinding. It is creating a new local variable by
name x
# But we are referring to x in y function call, so for the
definition of dynamic binding (?)
# should y() see x defined in the local scope instead of the
previously assigned value.
print(y())
return y()
x = 30 # This is rebinding in the same scope.
print(f())
$ python example.py
30
30
More information about the BangPypers
mailing list