Message183070
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. |
|
Date |
User |
Action |
Args |
2013-02-26 19:23:01 | Christopher.King | set | recipients:
+ Christopher.King, benjamin.peterson, r.david.murray, bogklug |
2013-02-26 19:23:01 | Christopher.King | set | messageid: <1361906581.44.0.262017644838.issue7423@psf.upfronthosting.co.za> |
2013-02-26 19:23:01 | Christopher.King | link | issue7423 messages |
2013-02-26 19:23:00 | Christopher.King | create | |
|