Created
August 4, 2008 18:25
-
-
Save jeremyBanks/3945 to your computer and use it in GitHub Desktop.
After reading PEP 342 [2010-01] i goofed around with simple generators, I guess
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
def mahgen(): | |
v = "START" | |
c = 0 | |
while 1: | |
v = yield (v, c) | |
c += 1 | |
def main(): | |
gen = mahgen() | |
print gen.send(None) # == gen.next() | |
print gen.send("PIE") | |
print gen.send("HAM") | |
print gen.send("MORE PIE") | |
print gen.send("CAKE") | |
if __name__ == "__main__": sys.exit(main()) | |
This file contains hidden or 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
('START', 0) | |
('PIE', 1) | |
('HAM', 2) | |
('MORE PIE', 3) | |
('CAKE', 4) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment