Multiline lamba implementation in python.
jgilbert.python at gmail.com
Wed Jun 13 01:48:41 CEST 2007
On 6/12/07, Facundo Batista <facundo at taniquetil.com.ar> wrote:
> Josh Gilbert wrote:
> > I don't expect multiline lambdas to be added to Python. I'm not so sure
> > that's a bad thing. Regardless, isn't it possible to write your own
> Yes, it is a bad thing.
> Why? Because it would another way to do something you can do in other
> The *only* big value of lambda is than you can code a function in a
> small place, like:
> bt = Button(...,...,..., lambda evt: None)
> If you want to grow that in multiline, just use a named function:
> def multilinefunct(...):
> Remember that the *only* difference between the two functions is that
> one is anonymous, and for other you have to came up with a name (name
> that if is well thought, actually adds readibility to your code).
> . Facundo
> Blog: http://www.taniquetil.com.ar/plog/
> PyAr: http://www.python.org/ar/
Guido doesn't want multiline lambdas, that's a really good reason not to add
them. They are, on the other hand, very useful at times. Even if he did add
multiline lambdas it's not certain that he would allow statements in them,
currently they're expression only. The beauty of my suggestion is that you
can define an anonymous multiline functions with statements in them.
I know that the standard Python response is that you might as well define a
function, indeed, the name might provide useful documentation. In reality,
however, the vast majority of my anonymous functions are callbacks (tends to
lead to names like mouseUp_callback) and functions passed into list
comprehensions. I don't want to have to name them, it breaks the flow. My
technique allows for anonymous functions of arbitrary complexity which is
what I really want.
I really don't think that I'm alone here, the lack of a multiline lambda has
been bemoaned for years (recently here
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list