Re: Functions as Objects, and persisting values

2007-11-05 Thread Bruno Desthuilliers
Falcolas a écrit : > Please help me understand the mechanics of the following behavior. > > def d(): > > header = 'I am in front of ' > def e(something): > print header + something > return e > > f = d() f('this') > > I am in front of this > de

Re: Functions as Objects, and persisting values

2007-11-05 Thread Rich Harkins
[snip] > The "thing" you observe here is a called a closure. It consists of the > local variables surrounding e. So as long as you keep a reference to e, > you keep one to the variables of d itself. > > Diez More specifically though it keeps references to the requested variables only: def clo

Re: Functions as Objects, and persisting values

2007-11-05 Thread Diez B. Roggisch
Falcolas schrieb: > Please help me understand the mechanics of the following behavior. > def d(): > header = 'I am in front of ' > def e(something): > print header + something > return e > f = d() f('this') > I am in front of this del(d) f(

Functions as Objects, and persisting values

2007-11-05 Thread Falcolas
Please help me understand the mechanics of the following behavior. >>> def d(): header = 'I am in front of ' def e(something): print header + something return e >>> f = d() >>> f('this') I am in front of this >>> del(d) >>> f('this') I am in front of this