On 25 September 2012 23:09, Ian Kelly <ian.g.ke...@gmail.com> wrote:

> On Tue, Sep 25, 2012 at 12:17 PM, Oscar Benjamin
> <oscar.j.benja...@gmail.com> wrote:
> > Also I think lambda functions might be able to keep the frame alive. Are
> > they by any chance being created in a function that is called in a loop?
>
> I'm pretty sure they don't.  Closures don't keep a reference to the
> calling frame, only to the appropriate cellvars.
>

OK, that's good to know.


>
> Also note that whether a function is a closure has nothing to do with
> whether it was defined by a lambda or a def statement.  In fact,
> there's no difference between functions created by one vs. the other,
> except that one has an interesting __name__ and the other does not.
> :-)


That's true but in my experience most lambda functions are defined inside
another function, whereas most ordinary functions are not. Also when
creating a closure with an ordinary function it's very clear what you are
doing (which is why I don't use lambda functions for this) so I think it's
a little easier to accidentally create a closure with a lambda function.

Oscar
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to