Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

python:coroutines [2015-11-07] – created dcaipython:coroutines [2020-04-19] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Python Coroutines ======
  
 +<code python>
 +# Sent values are returned by yield
 +def grep(pattern):
 +    print "Looking for %s" % pattern
 +    while True:
 +        line = (yield)
 +        if pattern in line:
 +            print(line)
 +            
 +g = grep("python")
 +g.next()
 +g.send("python generators rock!")
 +</code>