nested scopes

Robin Becker robin at jessikat.fsnet.co.uk
Fri Feb 2 19:46:55 EST 2001


In article <95fein$shj$1 at nnrp1.deja.com>, Jeremy Hylton
<jeremy at alum.mit.edu> writes
...
probaly correct analysis of maintainance elided.

The only difference on a name change would be the import as well as the
actual reference.

>I think that's a bit of an exageration :-).  I don't think there's a
>"whole point" to Python.
>
>> I can't figure out how any compiler is going to figure out
>> that
>>
>> def outer(name):
>>     exec name + '=1'
>>     def inner():
>>         return g
>>     return inner()
>>
>> can work if I call outer('g') so this must only be static scoping; if
>> it's static why should dynamic events like imports be clashing with
>> it. I suppose there's some attempt at code optimisation being pursued.
>
>Interesting point you raise.  The compiler is supposed to flag this as
>an error, just like import * and for exactly the same reason.  Dynamic
>name binding via exec or import * are at odds with static scoping -- and
>you shouldn't try to mix the two.  I'll have to fix this in the next
>release.

The implication of this is that we're forbidden to use exec if it
clashes with a statically scoped name or am I still being stupid?

Python is a joy to use because it lacks such pedantic restrictions.

>--
>-- Jeremy Hylton, <http://www.python.org/~jeremy/>
>
>
>Sent via Deja.com
>http://www.deja.com/

-- 
Robin Becker



More information about the Python-list mailing list