A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-April/052802.html below:

[Python-Dev] Re: Re: anonymous blocks

[Python-Dev] Re: Re: anonymous blocks [Python-Dev] Re: Re: anonymous blocksFredrik Lundh fredrik at pythonware.com
Thu Apr 21 15:11:23 CEST 2005
Bob Ippolito wrote:

>>> 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.

that's why you need a context object (=self, in this case).

    def iterman(self):
        yield "hello"
        print self.data
        yield "nice weather we're having"
        print self.data
        yield "goodbye"

also see:

    http://effbot.org/zone/asyncore-generators.htm

> If they did, then this use case could be mostly served by generators.

exactly.

</F> 



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4