Nested scope suggestion
John Thingstad
john.thingstad at chello.no
Wed Nov 28 09:54:24 EST 2001
I am somwhat upset that is seems impossible to to set variales in higher levels of the scope.
For example
def fun():
lst = []
y = lambda x: lst.append(x)
fun2(y)
works, but
def fun():
val = 0
y = lambda x: val = x
fun2(y)
does not. Here we create a new local val.
What I would like to write is:
def fun():
val = 0
y = lambda x: fun.val = x
fun2(y)
which seems to be in the same spirit as
class a:
def __init__(self, x)
pass
class b(a):
def __init__(self, x):
a.__init__(self, x)
Given that a function has a attribute __name__ it should be a simple matter to use introscpection to
resolve the assignement.
Any chance of this functionality being added to nested scopes?
More information about the Python-list
mailing list