[Python-Dev] Re: anonymous blocks
Bob Ippolito
bob at redivi.com
Thu Apr 21 13:04:45 CEST 2005
On Apr 21, 2005, at 6:28 AM, Fredrik Lundh wrote:
> Glyph Lefkowitz wrote:
>
>> Despite being guilty of propagating this style for years myself, I
>> have to disagree. Consider the
>> following network-conversation using Twisted style (which, I might
>> add, would be generalizable to
>> other Twisted-like systems if they existed ;-)):
>>
>> def strawman(self):
>> def sayGoodbye(mingleResult):
>> def goAway(goodbyeResult):
>> self.loseConnection()
>> self.send("goodbye").addCallback(goAway)
>> def mingle(helloResult):
>> self.send("nice weather we're having").addCallback(sayGoodbye)
>> self.send("hello").addCallback(mingle)
>
> def iterman(self):
> yield "hello"
> yield "nice weather we're having"
> yield "goodbye"
Which, more or less works, for a literal translation of the straw-man
above. However, you're missing the point. These deferred operations
actually return results. Generators offer no sane way to pass results
back in. If they did, then this use case could be mostly served by
generators.
-bob
More information about the Python-Dev
mailing list