Why read-only nested scopes?

Fernando Pereira pereira at cis.upenn.edu
Thu Sep 5 04:00:41 EDT 2002

On 9/5/02 2:41 AM, in article c0Dd9.6121$e5.1077322 at newsb.telia.net,
"Fredrik Lundh" <fredrik at pythonware.com> wrote:

> David Eppstein wrote:
>> I'm sure there were good reasons for this decision, but it leads to ugly
>> workarounds like making each nonlocal variable into a list and assigning
>> to x[0] instead of x...
> when you find yourself doing that, it's a sure sign that you're
> no longer using python to write python code...
There is a reason why this may be puzzling to some. Other languages with
non-local lexically scoped variables seem to come in two varieties: those
like Pascal or Common Lisp in which all variables name assignable locations,
and those like ML or Haskell in which all variables name values, and no
bindings be changed. Python is a hybrid, in that variables name values,
local and global bindings can be changed dynamically, but bindings
established at intermediate scopes cannot. This is not a criticism of Python
--- in my experience with languages like Pascal and Common Lisp, assignments
to non-local, non-global variables are more confusing than they are worth
--- but a suggestion of why it may seem strange at first.

-- F

More information about the Python-list mailing list