On Oct 15, 1:51 pm, Michele Simionato <[EMAIL PROTECTED]> wrote: > On Oct 15, 1:01 pm, looping <[EMAIL PROTECTED]> wrote: > > > So if I understand what Michele wrote (thanks too), when a function is > > defined (with def), no scope is saved and every variable value not > > passed in parameter is lost ? It means that variable value come from > > the outer scope when the function is called ? > > Yes, in my example you get the value of "i" at the function *calling* > time, > not at the function definition time. If you want to store the value at > the > definition time, you must use the default argument trick: > > funclist = [] > for i in 1,2,3: > def f(i=i): > print i > funclist.append(f) > > Michele Simionato
Thanks Michele, now I understand how it works and I learned something new. Not a bad day... -- http://mail.python.org/mailman/listinfo/python-list