[Twisted-Python] some callback function params problems

Tim Allen screwtape at froup.com
Tue Jun 9 05:55:06 EDT 2009

On Tue, Jun 09, 2009 at 05:31:52PM +0800, hoooooosety wrote:
> Is there a common way to solve the problem like this. I mean I can
> still keep the separate functions as the look like now,

I do it like this:

    def deferCompoundFunc(paramA, paramB):
	d = deferDoSomeInsert(paramA, paramB)
	d.addCallback(lambda ignored: deferDoSomeDelete(paramA, paramB))
	return d

(Actually I normally call the lambda's parameter "_" rather than
"ignored" because it's faster to type, and makes pylint not complain
about unused variables)

If you're learning Twisted for the first time, get prepared to get very
friendly with lambda. :)

More information about the Twisted-Python mailing list