anonymous functions/expressions without lambda?

Paul Miller paul at fxtech.com
Thu Apr 28 11:51:28 EDT 2005


Michael Hoffman wrote:

> That's what lambda does. But it's going away, you'll have to use def 
> when it does, unless the language designers come up with something better.

Yeah, I'm using lamda now it works nicely/cleanly.

> If a lot of the bindings are actually setting variables, you could do 
> something like this:
> 
> def attrsetter(obj, name, 1):
>     def _return_func(value):
>         return setattr(obj, name, value)
> 
>     return _return_func
> 
> bind('a', attrsetter(foo, "var", 1))
> bind('a', attrsetter(foo, "var", 2))

Ah, perfect. Thanks!




More information about the Python-list mailing list