"Uwe Schmitt" <uw*********@procoders.net> wrote in message
news:c6************@hades.rz.uni-saarland.de...
I just tried (Python 2.3)
Which did not change anything in this regard...
li = [ lambda x: x*a for a in range(10) ]
which, except for function __name__ and func_name attributes, translates
(unabbreviates) to
li = []
for a in range(10):
def tem(x): return x*a
li.append(tem)
del tem
which is equivalent to
li = []
for a in range(10):
def tem(x): return x*__multiplier
li.append(tem)
__multiplier = a
del a, tem
which results in
li[0](1) = 9
...
li[9](1) = 9
As one would expect from second translation above if not the first.
Its funny how some people expect default parameter objects to be
re-calculated on every call instead of just once, while others sometimes
expect global vars to be evaluated just once instead of on every call ;-)
The question of whether free vars within lambdas within list comps should
get 'early binding' instead of the usual late binding was discussed on
Py-Dev list last fall and some this winter. I believe Guido recently said
no change.
Terry J. Reedy