Christopher King added the comment: This is a crazy and unexpected behavior. (Moreover, the fact that Python has dynamic scope *only if you forget to initialize a variable* is even more crazy and unexpected.) To provide unsurprising behavior (i.e. behavior compatible with that of a list comprehension) the generator above should "unwrap" (i.e. reduce) to:
def g1(x): for y in 'c': yield x+y l = [] for x in 'ab': l.append(g1(x)) print l print map(list, l) i.e. the variables referenced by, but not initialized by, the innermost generator should add extra parameters to the generated generator function. ---------- nosy: +Christopher.King _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue7423> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com