PEP 227 (was Re: Nested scopes resolution -- you can breathe again!)

Russell E. Owen owen at astrono.spamwashington.emu
Fri Mar 2 10:59:12 EST 2001


In article <KNSz0UAhfpn6EwZj at jessikat.fsnet.co.uk>, Robin Becker <robin at jessikat.fsnet.co.uk> wrote:

>In article <mailman.983466367.2968.python-list at python.org>, Jeremy
>Hylton <jeremy at alum.mit.edu> writes
>>Or: global NAME in FUNCTION
>>
>>def eggs():
>>    z = 2
>>    def spam():
>>        def inner():
>>            global x in spam, z in eggs
>>            x += 1
>>            z += x
>>        x = 23
>>        inner()
>>
>>Jeremy
>>
>I like that a lot better than having it default possibly wrongly, but
>how would this be doable/spelled in the lambda case?

As somebody else pointed out, a nice possible notation for that has been proposed. 

lambda arg1, arg2; externalVar1, externalVar2: expression

One interesting question is whether we could just implement that and throw out the rest of the nested scope proposal. If so, that gets my vote, followed by an explicit keyword for external variables, followed by chucking the whole thing and living with ugly lambdas. I loathe the idea of externally declared variables polluting a function's namespace. That works fine in languages that make you declare all variables, but I do not think it is safe or reasonable in Python.

-- Russell



More information about the Python-list mailing list