Created
September 4, 2014 10:32
-
-
Save davidbj/784d5fb8a6baac0a9bfc to your computer and use it in GitHub Desktop.
python yield demo
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 | |
| #-*- coding:utf-8 -*- | |
| #Function: python yield demo | |
| Queue=[1, 2, 3, 4, 5, 6] | |
| def foo(regex): | |
| print "start..." | |
| while True: | |
| var=(yield) | |
| if var == regex: | |
| print var | |
| if __name__ == "__main__": | |
| command = foo(4) | |
| command.next() //echo "start..." | |
| for i in Queue: | |
| command.send(i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment