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-May/053507.html below:

[Python-Dev] Breaking off Enhanced Iterators PEP from PEP 340

[Python-Dev] Breaking off Enhanced Iterators PEP from PEP 340Michele Simionato michele.simionato at gmail.com
Sat May 7 07:45:30 CEST 2005
On 5/6/05, Steven Bethard <steven.bethard at gmail.com> wrote:
> FWIW, I'm +1 on this.  Enhanced Iterators
>  * updates the iterator protocol to use .__next__() instead of .next()
>  * introduces a new builtin next()
>  * allows continue-statements to pass values to iterators
>  * allows generators to receive values with a yield-expression
> The first two are, I believe, how the iterator protocol probably
> should have been in the first place.  The second two provide a simple
> way of passing values to generators, something I got the impression
> that the co-routiney people would like a lot.

Thank you for splitting the PEP. Conceptually, the "coroutine" part  
has nothing to do with blocks and it stands on its own, it is right
to discuss it separately from the block syntax.

Personally, I do not see an urgent need for the block syntax (most of
the use case can be managed with decorators) nor for the "couroutine"
syntax (you can already use Armin Rigo's greenlets for that).

Anyway, the idea of passing arguments to generators is pretty cool,
here is some code I have, adapted from Armin's presentation at the
ACCU conference:

from py.magic import greenlet

def yield_(*args):
    return greenlet.getcurrent().parent.switch(*args)

def send(key):
    return process_commands.switch(key)

@greenlet
def process_commands():
    while True:
        line = ''
        while not line.endswith('\n'):
            line += yield_()
        print line,
        if line == 'quit\n':
            print "are you sure?"
            if yield_() == 'y':
                break
            
process_commands.switch() # start the greenlet

send("h")
send("e")
send("l")
send("l")
send("o")
send("\n")

send("q")
send("u")
send("i")
send("t")
send("\n")
  

Michele Simionato
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