anonymous functions/expressions without lambda?

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


I see lambda is "going away", so I want to use something that will be 
around for awhile.

All I want to do is provide an "inline function" as an argument to 
another function.

For example, let's say I have a function which binds a key to a function 
call. I want to do something "simple" in this function call, and I have 
a lot of bindings, so I don't want to have a ton of tiny little 
functions scattered around:

	def setVarTo1():
		foo.var = 1
	def setVarTo2():
		foo.var = 2

	bind('a', setVarTo1)
	bind('b', setVarTo2)

Instead, I'd like to do something like this:

	bind('a', foo.var = 1)
	bind('b', foo.var = 2)

What's the recommended way to do something like this?

Note that the bind function is implemented in "C", and I am embedding 
the interpreter.




More information about the Python-list mailing list