"Schüle Daniel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> block (Python forbids the rebinding of variables coming from an >> enclosing but non-global scope, to avoid facing this issue). > > I am not sure what you mean here > can you elaborate on this please > > >>> def a(): > ... q = [] > ... def b(x): > ... def c(y): > ... def d(z): > ... q.append(x) > ... q.append(y) > ... q.append(z) > ... d(1) > ... c(2) > ... b(3) > ... return q > ... > >>> a() > [3, 2, 1]
You are mutating q, not rebinding it. As another poster discovered, replacing the appends by the nominally equivalent augmented assignments: q += [x] #etc does not work. Since the compiler does not know the type of q, it assumes that it needs to be rebound and compiles code to do so, even though here is would be to the same object. That makes q an (uninitialized) local. Terry Jan Reedy
-- http://mail.python.org/mailman/listinfo/python-list