python: lexical or dynamic scope?
Mark Wooding
mdw at distorted.org.uk
Wed May 14 09:28:22 EDT 2008
Arnaud Delobelle <arnodel at googlemail.com> wrote:
> AFAIK, Python has lexical scoping, with the restriction that
> non-global non-local names cannot be rebound.
I believe so.
It's possible to implement (shallow) dynamic binding as a Python context
manager, though it involves a little unpleasantness with sys._getframe
to get hold of the caller's variables. See
http://www.distorted.org.uk/~mdw/hacks/fluid.py
That Python can do this (and fairly simply) speaks well of its
flexibility and dynamic nature.
I don't know how to make it work properly with multi-threading,
unfortunately.
-- [mdw]
More information about the Python-list
mailing list