Created
July 17, 2009 02:17
-
-
Save cdent/148823 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
class Addable(object): | |
def __init__(self): | |
self.holder = deque() | |
def adder(self): | |
while True: | |
try: | |
self.holder.append((yield)) | |
except GeneratorExit: | |
return | |
def show(self): | |
while True: | |
try: | |
yield self.holder.popleft() | |
except IndexError: | |
return | |
def do2(): | |
a = Addable() | |
adder = a.adder() | |
shower = a.show() | |
adder.next() | |
for i in ['you', 'sexy', 'thing']: | |
adder.send(i) | |
print shower.next() | |
for i in ['YOU', 'SEXY', 'THING']: | |
adder.send(i) | |
print shower.next() | |
print "remains" | |
for remains in shower: | |
print remains | |
shower = a.show() # gotta reboot the shower | |
adder.send('so done now') | |
print shower.next() | |
if __name__ == '__main__': | |
do2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment