python: lexical or dynamic scope?

Carl Banks pavlovevidence at gmail.com
Tue May 13 17:59:16 EDT 2008


On May 13, 3:27 pm, globalrev <skanem... at yahoo.se> wrote:
> i cant figure outif python has lexical or general scope.
>
> it seems functions have lexical scope but with some restrictions and

Yes.  (You can't modify a local variable from an inner scope--this
will change in Python 3.0.)

> some non-function scopes are dynamic?

No: I presume you mean the class statement, which is the only thing
other than def that introduces a scope in Python, but it's neither
dynamic nor lexical.  In fact it's closed: you can only access
variables in a class scope from that scope, and not from enclosed
scopes (e.g., method defintions) at all.


Carl Banks



More information about the Python-list mailing list