[Python-Dev] Let's just keep lambda (original) (raw)

Adam Olsen rhamph at gmail.com
Thu Feb 9 23:52:06 CET 2006


On 2/9/06, Valentino Volonghi aka Dialtone <dialtone at divmod.com> wrote:

Let's consider this piece of code (actual code that works today and uses twisted for convenience):

def dostuff(result): if result == 'Initial Value': d2 = workonresultandreturnadeferred(result) d2.addCallback(println) return d2 return 'No work on result' def println(something): print something d1 = someoperationthatresultsinadeferred() d1.addCallback(dostuff) d1.addCallback(lambda : reactor.stop()) reactor.run()

PEP 342 provides a much better alternative:

def do_stuff(): result = (yield some_operation()) something = (yield work_on_result(result)) print something reactor.stop() # Maybe unnecessary?

reactor.run(do_stuff())

Apparantly it's already been applied to Python 2.5: http://www.python.org/dev/doc/devel/whatsnew/node4.html

Now that may not be the exact syntax that Twisted provides, but the point is that the layout (and the top-to-bottom execution order) is possible.

-- Adam Olsen, aka Rhamphoryncus



More information about the Python-Dev mailing list