Problem with Lexical Scope



I am not completely knowledgable about the status of lexical scoping in
Python, but it was my understanding that this was added in a long time
ago around python2.1-python2.2

I am using python2.4 and the following code throws a "status variable"
not found in the inner-most function, even when I try to "global" it.

def collect(fields, reducer):
def rule(record):
status = True
def _(x, y):
cstat = reducer(x, y)
if status and not cstat:
status = False
return y
return reduce(_, [record[field] for field in fields])
return rule

What gives?

.



Relevant Pages

  • Simple newbie question about parameters handling in functions (or am I dump or what?)
    ... I am totaly new to Python, although I have quite strong developer ... function can change wathever parameters reffers to. ... presonal not understanding comes from this) ... def ChangeList: ...
    (comp.lang.python)
  • Re: Why no lexical scoping for a method within a class?
    ... def a: ... Lexical scoping is going on here, you're just mistaking what's being scoped; it's the |self| in |b|, which is in scope because it's a parameter. ... then Python would whinge mightily at you, claiming that it knoweth naught of this |x| attribute of which you speak, and can it go home now for this is a silly place. ... The |self| in |b| is still in lexical scope, ...
    (comp.lang.python)
  • Lexical Scope
    ... I must be misunderstanding how Python 2.3 handles lexical scoping. ... def run: ...
    (comp.lang.python)
  • getattr(foo, foobar) not the same as foo.foobar?
    ... ...: def show: ... This breaks my understanding of id, the is operator, and ... I'm using Python 2.5.2. ... Dave Kuhlman ...
    (comp.lang.python)
  • Re: Use empty string for self
    ... argument but understanding that it's not really something that is always ... I'm trying to train myself to see ... def doittoitas def doittoit ... Python by analogy, but don't fall into the trap of trying to write C++ ...
    (comp.lang.python)