Re: Problem with Lexical Scope



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

.



Relevant Pages

  • Re: properties access by name
    ... Since rwproperty appears to use descriptors just like regular ... def title: ... but I want to set my property through the provided setter. ...
    (comp.lang.python)
  • AJAX Post requests
    ... I have a simple web server using BaseHTTPServer, and the def do_POST ... but when I send an AJAX POST to it it does nothing (I've tried to just ... although it does for a regular POST request. ... ctype, pdict = cgi.parse_header(self.headers.getheader ...
    (comp.lang.python)
  • Re: AJAX Post requests
    ... I have a simple web server using BaseHTTPServer, and the def do_POST ... but when I send an AJAX POST to it it does nothing (I've tried to just ... although it does for a regular POST request. ...
    (comp.lang.python)
  • Re: metaclass and customization with parameters
    ... In the lack of this hack, the def would run only at the first ... The def statement is rerun every loop, ... blog: http://rascunhosrotos.blogspot.com ...
    (comp.lang.python)
  • Re: closures and dynamic binding
    ... is seen by many to be a hack as well, ... If one wants multiple closures with a variable number of arguments, one should use a def statement and some other binding method, such as given below ... lst = ... def f: return lambda: i ...
    (comp.lang.python)