[issue13595] Weird behavior with generators with self-referencing output.

2011-12-13 Thread Pyry Pakkanen
Pyry Pakkanen added the comment: Oh, I was sure it had to do with binding issues. I just couldn't put my finger on it because the behavior seemed so counterintuitive. Thanks for clearing things up. I can now work around this feature. -- ___ Python t

[issue13595] Weird behavior with generators with self-referencing output.

2011-12-13 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc added the comment: This is expected, and is due to the late binding of the "label" variable in the "item+label" expression. Look at the example below: >>> l = [lambda item: item + label for label in "ab"] >>> f1, f2 = l >>> print f1(''), f2('') b b For the lambda functio

[issue13595] Weird behavior with generators with self-referencing output.

2011-12-13 Thread Pyry Pakkanen
New submission from Pyry Pakkanen : The following self-referencing generator has incorrect output: def ab_combinations(): #'', 'a', 'b', 'aa', 'ab', 'ba', 'bb', 'aaa', ... def _deferred_output(): yield "" tees = tee(output) #This definition works fine: '', 'a', '