List of Functions

Dan Sommers dan at tombstonezero.net
Mon Mar 28 08:39:20 EDT 2016


On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote:

> As for Python, I don't feel a great need for anonymous functions.
> However, I keep running into a need for anonymous classes, or, rather,
> classless objects. Not a biggie. I just create a one-off inner class
> and instantiate it, but I do appreciate Java's syntactic innovation.

And I always curse Java for having to create an inner class and a method
when all I need is a simple function.  :-)

I think it's Steven D'Aprano who keeps pointing out that you can always
name your tiny helper functions instead of using lambda:

    def some_complex_function():
        def f(x) = x + 2
        some_library_that_wants_a_callback(f)
        some_library_that_wants_a_callback(lambda x: x + 2)

Both calls to some_library_that_wants_a_callback run the same.



More information about the Python-list mailing list