[issue28241] Nested fuctions Unexpected behaviour when stored in a list and called after.

2016-09-21 Thread artxyz
artxyz added the comment: I got it now. Thanks! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue28241] Nested fuctions Unexpected behaviour when stored in a list and called after.

2016-09-21 Thread R. David Murray
R. David Murray added the comment: Note also that your first example worked only because your loop variable was named i. If you used, say, 'j', you'd get the same result as in your second example. This is because the closure is over the named variable, and both in your definition loop and yo

[issue28241] Nested fuctions Unexpected behaviour when stored in a list and called after.

2016-09-21 Thread Zachary Ware
Zachary Ware added the comment: See https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result Note that `lambda: x**2` is equivalent to `def FUN(): return x**2`. -- nosy: +zach.ware resolution: -> not a bug stage:

[issue28241] Nested fuctions Unexpected behaviour when stored in a list and called after.

2016-09-21 Thread artxyz
New submission from artxyz: Python 2.7.11 GCC 4.8.4 Getting weird results when define a nested function in a loop and store them in a list x = list() for i in xrange(5): def FUN(): print i x.append(FUN) Calling functions from list using index works fine: