Problem with Lexical Scope
jslowery at gmail.com
jslowery at gmail.com
Mon Dec 12 03:03:43 EST 2005
Well, I think I found a nasty little hack to get around it, but I still
don't see why it doesn't work in the regular way.
def collect(fields, reducer):
def rule(record):
# Nasty hack b/c can't get lexical scoping of status to work
status = [True]
def _(x, y, s=status):
cstat = reducer(x, y)
if s[0] and not cstat:
s[0] = False
return y
reduce(_, [record[field] for field in fields])
return status[0]
return rule
More information about the Python-list
mailing list